springboot 知识点
---恢复内容开始---
1springBoot项目引入方式,
1,继承自父 project (需要没有付项目才能用,一般我们的项目都会有 父 项目 所以 这种方式不推荐 ,记住有这种方式 就可以了)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
2,写dependencyManagement ,推荐 使用这种方式,没有什么限制,dependencyManagement 包着 的依赖不会直接使用,只有在外面 的 dependencies 上面写了才会生效,并且这时候可以不写 版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2 springBoot 的启动
第一种方式:SpringApplication application = new SpringApplication();
Set<Object> set = new HashSet<>();
set.add(Main.class );
application.setSources(set);
ConfigurableApplicationContext context = application.run(args);
第二种方式: ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
备注:上面代码需要引入 springweb
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3 springBoot 的启动 会把 Sources 当做 配置类,相当有了 @SpringBootConfiguration 注解,所以可以不写@SpringBootConfiguration
4 springBoot 的默认配置文件是 application.properties
4 springBoot 获取 配置文件的三种方式
1,通过context 回去环境对象
context.getEnvironment().getProperty("local.port")
2,注入环境对象
@Autowired
private Environment environment;
3,使用 @Value("${local.ip}") 在属性上面注入
备注: value的值 格式 ${key}
5 springBoot propertise 的 配置 支持 内部引用 (可以直接在value 中通过表达式接近应用key 对应的 value )
local.ip=127.0.0.1
local.port=8080
local.ipAndPort=${local.ip}:${local.port}
6 配置文件去默认值(如果key 不存在,且不设置默认值或报错) 但是通过 getEnvironment().getProperty("local.def","000000") 这种方式获取不会报错,只会返回null
${key:默认值} (在没有这个key 的时候生效)
例子:@Value("${local.df:99}") (local.df不存在)
7 修改配置文件的位置
默认配置文件才classpath: 根目录 或者 classpath:config/ 目录
8 修改配置文件名
1 修改main 方法启动参数 --spring.config.name=配置文件名(不要拓展名)
2 修改任意 的 路径和文件名 --spring.config.location=classpath:conf/app.properties
3 可以是 file:协议的地址 --spring.config.location=file:D:\eclipsej2ee\springBoot\src\main\resources\conf\app.properties
4 可以有多个 配置文件(逗号隔开) -spring.config.location=file:path,classpath:path2,,classpath:path2
5 可以通过 @PropertySource("classpath:conf/app.properties") 注解方式指定 配置文件 的路径
注:@PropertySources 可以写多个 @PropertySource
注2:可以直接写多个 @PropertySource
6 使用 @ConfigurationProperties(prefix="local") 直接指定 配置文件
注:若果 key 没有 前缀,那么不配置前缀就可以
9,springBoot 的 配置文件可以使yml
10 ,注入集合或者数组 (亲测,必要指定泛型类型),不能是set
key[0]=value0
key[1]=value1
key[2]=value2
11 通过编程方式动态指定 配置文件,需要实现 EnvironmentPostProcessor 接口 并且 在 META-INF/spring.factories 中注册
spring.factories --> org.springframework.boot.env.EnvironmentPostProcessor=com.zyk.springBoot.main.MyEnvironmentPostProcessor
代码实现 environment.getPropertySources().addLast(propertySource); propertySource好像就是以前spring 的placeHoder
spring的 profile
12 指定profile
默认会加载application.properties 设置类 app.setAdditionalProfiles("test"); 会额外加载 application-test.properties,如果 test环境配置和 默认环境配置有key重复,那么 用额外的,如果是数组,不会合并,而是只用额外环境
备注:setAdditionalProfiles 设置额外配置文件 (可以添加多个额外配置)
备注2:--spring.profiles.active=test 也可以设置环境(额外激活)
备注3:--spring.profiles=test 仅仅激活test,不激活默认的环境
13 @Profile 修饰的 Bean 只有在指定环境面 才会生效 (可以指定在类型前面)
spring的 Condition
14 Condition 接口配合 @Conditional 注解使用,修饰@Bean 只有条件成立才,spring才会 调用@Bean 的的方法,
自定义Condition 例子:
@Bean
@Conditional(MyCondition1.class)
public String gbk(){
return "GBK";
}
@Bean
@Conditional(MyCondition2.class)
public String utf(){
return "utf-8";
}
只有MyCondition2.class 接口函数的 方法放回true 的时候才会产生
spring 提供大量默认的Condition注解
备注1:@Conditional 成立需要全部条件 true
备注2:@Conditional 有大量 类似 @ConditionalOn* 的注解,只有单满足 的时候才转配 @Bean
@ConditionalOnBean
@ConditionalOnClass
@ConditionalOnJava
@ConditionalOnExpression
@ConditionalOnNotWebApplication
@ConditionalOnSingleCandidate
spring @Enable*注解
1,@EnableAsync 注解开启后 使用 异步运行后, @Async 修饰的方法 会异步执行(不是代理对象,估计spring是直接改了 这个方法的二进制码 )
15 @Import 导入一个需要spring管理的 类 (可以是配置类或者是普通bean)
注:@Import 可以指向 ImportSelector 接口的实现类,在接口函数中指定 导入的类(接口与方法返回值是 类名全称字符数组)
注2: 可以写 ImportBeanDefinitionRegistrar 的 实现类 用来注册bean
16 spring注解的特点,任意一个自定义注解写入spring 配置类里面,那么这个自定义注解的全部父注解(spring认识的)都会生效 (N层都生效)
17 @EnableAutoConfiguration 的作用 (classpath 下面的 META-INF 里面 spring 工厂文件里面的接口对应的 值都加入到 spring 管理)
1,可以在 META-INF 中写上 org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.zyk.springBoot.Parent
这样 spring会把 Parent 加入spring管理(如果 Parent 是 类加入管理,如果 Parent 是配置 同样),并且上面这种写法的申明的配置 可以被另一的jar(别的项目模块)包使用
注2: 这个注解可以通过 spring.boot.enableautoconfiguration=ture/false 启用或者关闭(可以卸载 application.properties 配置文件 或者 args )
18 springBoot 的事件监听 需要继承 ApplicationEvent ,实现 MyApplicationListener ,需要先注册监听器,然后发布事件
例子:
SpringApplication app = new SpringApplication(Main.class);
app.addListeners(new MyApplicationListener());
ConfigurableApplicationContext context = app.run(args);
启用这个监听器需要启用才能接受事件,启动的方式可以通过
1 任意方式吧监听器加入 spring 容器中 (当做普通bean 加入就可以)
2 在 SpringApplication app = new SpringApplication(Main.class); app.addListeners(new MyApplicationListener());
3 在 配置文件 application.properties 中写入 context.listener.classes=com.zyk.springBoot.event.MyApplicationListener (这种方法和 DelegatingApplicationListener 有关)
4 可以 不实现 ApplicationListener 直接在一个方法中写上注解 @EventListener (参数决定可以接受什么类型的 事件 ,参数类型任意,Object 可以接受任何类型 ) (和 EventListenerMethodProcessor 这个 处理进程类有关 )
@EventListener
public void listener1( MyApplicationEvent event){
System.out.println( " 直接接收: " + event.getSource() );
}
5 在工厂配置文件里面 去 org.springframework.boot.SpringApplicationRunListener=。。。。。
19 springBoot 的拓展分析
是一种方式: 实现 接口 ApplicationContextInitializer ,然后在 加入到容器 springApplication.addInitializers( new MyApplicationContextInitializer()); 这个接口函数中有 springcontext 可以在容器启动的 过程中做一些事情
备注1: 不能直接加入到spring容器(应为这个很早,不想 事件监听器)
备注2: 这时候容器管理的类好没有加载完毕,不能取到spring管理的类(只有最初始的6个类)
第二种方式 配置文件配置 context.initializer.classes=com.zyk.springBoot.event.MyApplicationContextInitializer
第三种: 写在工厂配置文件里面 去 org.springframework.context.ApplicationContextInitializer=。。。。。
20 CommandLineRunner在容器成功启动的最后一步回掉 (比ApplicationContextInitializer 靠后 ),这时候容器已经启动
1备注直接加入容器就生效
2@Order(100) 修改顺序 (数字大的后执行)
21 ApplicationRunner 类似( ApplicationRunner 的 参数 是 ApplicationArguments 的封装) ,CommandLineRunner 取得main的args 的原值
22 关闭 springBoot 的 banner app.setBannerMode(Banner.Mode.OFF);
23 @SpringBootApplication 默认扫描的是当前包,和子包 可以通过 scanBasePackages指定扫描包
24 自定义 banner 写一个banner.txt 位于classpath 就会制动 使用这个文件里面的 banner
25 可以通过 在配置文件里面写入 banner.location 指定banner 位置 banner.cherset 指定编码
26 spring 支出 图片的banner 只要命名为 banner.图片格式就可以
27 banner.img.location 指定位置
springBoot 的运行流程分析
没做记录
springBoot web方面
28 @RestController 和@Controller 类似,区别在于相当于在每个 方法都写上 @ResponseBody (springWeb 带有的 不是 springBoot独有) (4.0以后)
29 提供了大量的 @GetMapping 之类的注解用来代替 @RequestMapping 每次需要指定 method (4.3 以后)
30 springBoot 指定前缀和后缀 (springboot 默认不支持jsp ,需要映入 tomcat-embed-jasper 才能支持)
spring.mvc.view.prefix=/WEB_INF/jsp
spring.mvc.view.suffix=.jsp
31 指定端口 server.port=8080
32 对于参数的传递到 页面视图传统方式是通过 在reques 里面设置属性,现在可以通过 Model 或者 ModelAndView
33 springBoot 使用 freemarker (测试没有成功,)
34 访问静态资源 和 ResourceProperties 有关,里面定义了 那些目录可以直接访问
spring.resources.staticLocations=.... 可以修改
35 在 SpringBootApplication 上使用@ServletComponentScan 注解后,Servlet、Filter、Listener 可以直接通过 @WebServlet、@WebFilter、@WebListener 注解自动注册,无需其他代码。这种仅支持servlet3.0以后
或者 通过 ServletRegistrationBean (这种可以支持servlet2.5以前)
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new MyServlet(), "/xs/*");
}
备注 :还有FilterRegistrationBean ServletListenerRegistrationBean
36 使用 jetty 启动 ,需要排除 tomcat 然后 加入 (不排除好像也可以)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
spring-boot-autoconfigure/1.5.8.RELEASE/spring-boot-autoconfigure-1.5.8.RELEASE-sources.jar 里面有很多的配置可以参考
37 springBoot 里面使用拦截器 (HandlerInterceptor,WebMvcConfigurerAdapter)
步骤如下:
1 写一个 类实现 HandlerInterceptor
2 写一个class 集成 WebMvcConfigurerAdapter
3 在 WebMvcConfigurerAdapter 的 方法中加入 添加 拦截器
38 自定义异常处理
1 方式1 (springBoot 才有)
实现 ErrorPageRegistrar(需要加入到spring管理) (ErrorPage 对象可以对应 不同状态码,不同异常跳转到不同地址(这个地址可以是页面或者action) )
在 ErrorPageRegistrar 里面添加 ErrorPage 对应的异常和异常处理地址的关系
方式 2 使用 SimpleMappingExceptionResolver 类,并且加入到 spring管理
方式 3 使用 实现 HandlerExceptionResolver 接口 ,并且加入到spring管理
方式4 @ExceptionHandler 注解方式 ( 默认只能处理当前controller 里面你的异常,在类前面 加上 @ControllerAdvice可以处理全部异常,优先级低于类同控制类里面的定义的 )
39 @ControllerAdvice 的作用
把@ControllerAdvice注解内部使用@ExceptionHandler、@InitBinder、@ModelAttribute注解的方法,应用到所有的 @RequestMapping注解的方法。不过只有当使用@ExceptionHandler最有用,另外两个用处不大。
40 继承 EmbeddedServletContainerCustomizer 可以 对 servlet 容器的启动进行设置
方法2 直接在@Bean 上返回一个 EmbeddedServletContainerCustomizer 对象
41 实现 AbstractRoutingDataSource 可以 对spring 数据源进行切换 (spring 会去这里面取数据源 )
---恢复内容结束---
1springBoot项目映入方式,
1,集成父 project
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
2,写dependencyManagement
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2 springBoot 的启动
1 SpringApplication application = new SpringApplication();
Set<Object> set = new HashSet<>();
set.add(Main.class );
application.setSources(set);
ConfigurableApplicationContext context = application.run(args);
2 ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
3 springBoot 的启动 会把 Sources 当做 配置类,相当有了 @SpringBootConfiguration 注解,所以可以不写@SpringBootConfiguration
4 springBoot 的默认配置文件是 application.properties
4 springBoot 获取 配置文件的三种方式
1,通过context 回去环境对象
context.getEnvironment().getProperty("local.port")
2,注入环境对象
@Autowired
private Environment environment;
3,使用 @Value("${local.ip}") 在属性上面注入
备注: value的值 格式 ${key}
5 springBoot propertise 的 配置 支持 内部引用 (可以直接在value 中通过表达式接近应用key 对应的 value )
local.ip=127.0.0.1
local.port=8080
local.ipAndPort=${local.ip}:${local.port}
6 配置文件去默认值(如果key 不存在,且不设置默认值或报错) 但是通过 getEnvironment().getProperty("local.def","000000") 这种方式获取不会报错,只会返回null
${key:默认值} (在没有这个key 的时候生效)
例子:@Value("${local.df:99}") (local.df不存在)
7 修改配置文件的位置
默认配置文件才classpath: 根目录 或者 classpath:config/ 目录
8 修改配置文件名
1 修改main 方法启动参数 --spring.config.name=配置文件名(不要拓展名)
2 修改任意 的 路径和文件名 --spring.config.location=classpath:conf/app.properties
3 可以是 file:协议的地址 --spring.config.location=file:D:\eclipsej2ee\springBoot\src\main\resources\conf\app.properties
4 可以有多个 配置文件(逗号隔开) -spring.config.location=file:path,classpath:path2,,classpath:path2
5 可以通过 @PropertySource("classpath:conf/app.properties") 注解方式指定 配置文件 的路径
注:@PropertySources 可以写多个 @PropertySource
注2:可以直接写多个 @PropertySource
6 使用 @ConfigurationProperties(prefix="local") 直接指定 配置文件
注:若果 key 没有 前缀,那么不配置前缀就可以
9,springBoot 的 配置文件可以使yml
10 ,注入集合或者数组 (亲测,必要指定泛型类型),不能是set
key[0]=value0
key[1]=value1
key[2]=value2
11 通过编程方式动态指定 配置文件,需要实现 EnvironmentPostProcessor 接口 并且 在 META-INF/spring.factories 中注册
spring.factories --> org.springframework.boot.env.EnvironmentPostProcessor=com.zyk.springBoot.main.MyEnvironmentPostProcessor
代码实现 environment.getPropertySources().addLast(propertySource); propertySource好像就是以前spring 的placeHoder
spring的 profile
12 指定profile
默认会加载application.properties 设置类 app.setAdditionalProfiles("test"); 会额外加载 application-test.properties,如果 test环境配置和 默认环境配置有key重复,那么 用额外的,如果是数组,不会合并,而是只用额外环境
备注:setAdditionalProfiles 设置额外配置文件 (可以添加多个额外配置)
备注2:--spring.profiles.active=test 也可以设置环境(额外激活)
备注3:--spring.profiles=test 仅仅激活test,不激活默认的环境
13 @Profile 修饰的 Bean 只有在指定环境面 才会生效 (可以指定在类型前面)
spring的 Condition
14 Condition 接口配合 @Conditional 注解使用,修饰@Bean 只有条件成立才,spring才会 调用@Bean 的的方法,
自定义Condition 例子:
@Bean
@Conditional(MyCondition1.class)
public String gbk(){
return "GBK";
}
@Bean
@Conditional(MyCondition2.class)
public String utf(){
return "utf-8";
}
只有MyCondition2.class 接口函数的 方法放回true 的时候才会产生
spring 提供大量默认的Condition注解
备注1:@Conditional 成立需要全部条件 true
备注2:@Conditional 有大量 类似 @ConditionalOn* 的注解,只有单满足 的时候才转配 @Bean
@ConditionalOnBean
@ConditionalOnClass
@ConditionalOnJava
@ConditionalOnExpression
@ConditionalOnNotWebApplication
@ConditionalOnSingleCandidate
spring @Enable*注解
1,@EnableAsync 注解开启后 使用 异步运行后, @Async 修饰的方法 会异步执行(不是代理对象,估计spring是直接改了 这个方法的二进制码 )
15 @Import 导入一个需要spring管理的 类 (可以是配置类或者是普通bean)
注:@Import 可以指向 ImportSelector 接口的实现类,在接口函数中指定 导入的类(接口与方法返回值是 类名全称字符数组)
注2: 可以写 ImportBeanDefinitionRegistrar 的 实现类 用来注册bean
16 spring注解的特点,任意一个自定义注解写入spring 配置类里面,那么这个自定义注解的全部父注解(spring认识的)都会生效 (N层都生效)
17 @EnableAutoConfiguration 的作用 (classpath 下面的 META-INF 里面 spring 工厂文件里面的接口对应的 值都加入到 spring 管理)
1,可以在 META-INF 中写上 org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.zyk.springBoot.Parent
这样 spring会把 Parent 加入spring管理(如果 Parent 是 类加入管理,如果 Parent 是配置 同样),并且上面这种写法的申明的配置 可以被另一的jar(别的项目模块)包使用
注2: 这个注解可以通过 spring.boot.enableautoconfiguration=ture/false 启用或者关闭(可以卸载 application.properties 配置文件 或者 args )
18 springBoot 的事件监听 需要继承 ApplicationEvent ,实现 MyApplicationListener ,需要先注册监听器,然后发布事件
例子:
SpringApplication app = new SpringApplication(Main.class);
app.addListeners(new MyApplicationListener());
ConfigurableApplicationContext context = app.run(args);
启用这个监听器需要启用才能接受事件,启动的方式可以通过
1 任意方式吧监听器加入 spring 容器中 (当做普通bean 加入就可以)
2 在 SpringApplication app = new SpringApplication(Main.class); app.addListeners(new MyApplicationListener());
3 在 配置文件 application.properties 中写入 context.listener.classes=com.zyk.springBoot.event.MyApplicationListener (这种方法和 DelegatingApplicationListener 有关)
4 可以 不实现 ApplicationListener 直接在一个方法中写上注解 @EventListener (参数决定可以接受什么类型的 事件 ,参数类型任意,Object 可以接受任何类型 ) (和 EventListenerMethodProcessor 这个 处理进程类有关 )
@EventListener
public void listener1( MyApplicationEvent event){
System.out.println( " 直接接收: " + event.getSource() );
}
5 在工厂配置文件里面 去 org.springframework.boot.SpringApplicationRunListener=。。。。。
19 springBoot 的拓展分析
是一种方式: 实现 接口 ApplicationContextInitializer ,然后在 加入到容器 springApplication.addInitializers( new MyApplicationContextInitializer()); 这个接口函数中有 springcontext 可以在容器启动的 过程中做一些事情
备注1: 不能直接加入到spring容器(应为这个很早,不想 事件监听器)
备注2: 这时候容器管理的类好没有加载完毕,不能取到spring管理的类(只有最初始的6个类)
第二种方式 配置文件配置 context.initializer.classes=com.zyk.springBoot.event.MyApplicationContextInitializer
第三种: 写在工厂配置文件里面 去 org.springframework.context.ApplicationContextInitializer=。。。。。
20 CommandLineRunner在容器成功启动的最后一步回掉 (比ApplicationContextInitializer 靠后 ),这时候容器已经启动
1备注直接加入容器就生效
2@Order(100) 修改顺序 (数字大的后执行)
21 ApplicationRunner 类似( ApplicationRunner 的 参数 是 ApplicationArguments 的封装) ,CommandLineRunner 取得main的args 的原值
22 关闭 springBoot 的 banner app.setBannerMode(Banner.Mode.OFF);
23 @SpringBootApplication 默认扫描的是当前包,和子包 可以通过 scanBasePackages指定扫描包
24 自定义 banner 写一个banner.txt 位于classpath 就会制动 使用这个文件里面的 banner
25 可以通过 在配置文件里面写入 banner.location 指定banner 位置 banner.cherset 指定编码
26 spring 支出 图片的banner 只要命名为 banner.图片格式就可以
27 banner.img.location 指定位置
springBoot 的运行流程分析
没做记录
springBoot web方面
28 @RestController 和@Controller 类似,区别在于相当于在每个 方法都写上 @ResponseBody (springWeb 带有的 不是 springBoot独有) (4.0以后)
29 提供了大量的 @GetMapping 之类的注解用来代替 @RequestMapping 每次需要指定 method (4.3 以后)
30 springBoot 指定前缀和后缀 (springboot 默认不支持jsp ,需要映入 tomcat-embed-jasper 才能支持)
spring.mvc.view.prefix=/WEB_INF/jsp
spring.mvc.view.suffix=.jsp
31 指定端口 server.port=8080
32 对于参数的传递到 页面视图传统方式是通过 在reques 里面设置属性,现在可以通过 Model 或者 ModelAndView
33 springBoot 使用 freemarker (测试没有成功,)
34 访问静态资源 和 ResourceProperties 有关,里面定义了 那些目录可以直接访问
spring.resources.staticLocations=.... 可以修改
35 在 SpringBootApplication 上使用@ServletComponentScan 注解后,Servlet、Filter、Listener 可以直接通过 @WebServlet、@WebFilter、@WebListener 注解自动注册,无需其他代码。这种仅支持servlet3.0以后
或者 通过 ServletRegistrationBean (这种可以支持servlet2.5以前)
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new MyServlet(), "/xs/*");
}
备注 :还有FilterRegistrationBean ServletListenerRegistrationBean
36 使用 jetty 启动 ,需要排除 tomcat 然后 加入 (不排除好像也可以)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
spring-boot-autoconfigure/1.5.8.RELEASE/spring-boot-autoconfigure-1.5.8.RELEASE-sources.jar 里面有很多的配置可以参考
37 springBoot 里面使用拦截器 (HandlerInterceptor,WebMvcConfigurerAdapter)
步骤如下:
1 写一个 类实现 HandlerInterceptor
2 写一个class 集成 WebMvcConfigurerAdapter
3 在 WebMvcConfigurerAdapter 的 方法中加入 添加 拦截器
38 自定义异常处理
1 方式1 (springBoot 才有)
实现 ErrorPageRegistrar(需要加入到spring管理) (ErrorPage 对象可以对应 不同状态码,不同异常跳转到不同地址(这个地址可以是页面或者action) )
在 ErrorPageRegistrar 里面添加 ErrorPage 对应的异常和异常处理地址的关系
方式 2 使用 SimpleMappingExceptionResolver 类,并且加入到 spring管理
方式 3 使用 实现 HandlerExceptionResolver 接口 ,并且加入到spring管理
方式4 @ExceptionHandler 注解方式 ( 默认只能处理当前controller 里面你的异常,在类前面 加上 @ControllerAdvice可以处理全部异常,优先级低于类同控制类里面的定义的 )
39 @ControllerAdvice 的作用
把@ControllerAdvice注解内部使用@ExceptionHandler、@InitBinder、@ModelAttribute注解的方法,应用到所有的 @RequestMapping注解的方法。不过只有当使用@ExceptionHandler最有用,另外两个用处不大。
40 继承 EmbeddedServletContainerCustomizer 可以 对 servlet 容器的启动进行设置
方法2 直接在@Bean 上返回一个 EmbeddedServletContainerCustomizer 对象
41 实现 AbstractRoutingDataSource 可以 对spring 数据源进行切换 (spring 会去这里面取数据源 )
springboot 知识点的更多相关文章
- Springboot知识点
1. Spring boot简介 主要用来简化spring开发,快速地创建独立的spring项目,并且与云计算天然集成. 2. @Controller 标记一个类是Controller . 3. @ ...
- springboot知识点补充(一)
测试配置 @RunWith(SpringRunner.class) @SpringBootTest @Configuration @ActiveProfiles("test") p ...
- springboot知识点【笔记】
# **一.**Spring Boot 入门 ## 1.Spring Boot 简介 > 简化Spring应用开发的一个框架:>> 整个Spring技术栈的一个大整合:>> ...
- SpringBoot28 RabbitMQ知识点、Docker下载RabbitMQ、SpringBoot整合RabbtiMQ
1 RabbitMQ知识点 1.1 整体架构图 消息生产者将消息投递到exchange中,exchange会以某种路由机制将生产者投递的消息路由到queue中,消息消费者再从queue中获取消息进行消 ...
- springboot整合redis缓存一些知识点
前言 最近在做智能家居平台,考虑到家居的控制需要快速的响应于是打算使用redis缓存.一方面减少数据库压力另一方面又能提高响应速度.项目中使用的技术栈基本上都是大家熟悉的springboot全家桶,在 ...
- SpringBoot 系列教程之事务隔离级别知识点小结
SpringBoot 系列教程之事务隔离级别知识点小结 上一篇博文介绍了声明式事务@Transactional的简单使用姿势,最文章的最后给出了这个注解的多个属性,本文将着重放在事务隔离级别的知识点上 ...
- Spring和Springboot相关知识点整理
简介 本文主要整理一些Spring & SpringBoot应用时和相关原理的知识点,对于源码不做没有深入的讲解. 1. 思维导图 右键新窗口打开可以放大. 说明 使用@Configurati ...
- SpringBoot小知识点
记录SpringBoot的小知识点 一.在 Spring 上下文刷新之前设置一些自己的环境变量 1.实现 EnvironmentPostProcessor 接口 2.spring.factories ...
- SpringBoot(一)-- 知识点介绍
一.简介 Spring Boot是为了简化Spring应用的创建.运行.调试.部署等而出现的,使用它可以做到专注于Spring应用的开发,而无需过多关注XML的配置.简单来说,它提供了一堆依赖打包,并 ...
随机推荐
- innodb_trx, innodb_locks, innodb_lock_waits
如果两个事务出现相互等待,则会导致死锁,MySQL的innodb_lock_wait_timeout参数设置了等待的时间限制,超时则抛异常. select @@innodb_lock_wait_tim ...
- 从用户输入url到页面最后呈现 发生了些什么?
一.浏览器获取资源的过程: 1.输入url 2.浏览器解析url,获得主机名 3.将主机名转换成服务器ip地址(查找本地DNS缓存列表,如果没有则向默认的DNS服务器发送查询请求) 4.浏览器建立一条 ...
- windows server2008服务器下XAMPP集成环境配置apache的SSL证书:
1.在腾讯与申请的免费SSL证书.按其要求配置,并提交申请,进行审核,审核通过,获得一年使用的SSL免费证书. 2.按下面的要求,进行SSL证书安装配置.本人在配置XAMPP下的apache时,无需复 ...
- python Django 之 Model ORM inspectdb(数据库表反向生成)
在前一篇我们说了,mybatis-generator反向生成代码. 这里我们开始说如何在django中反向生成mysql model代码. 我们在展示django ORM反向生成之前,我们先说一下怎么 ...
- selenium(四)操作cookie,伪造cookie
简介: Cookie,有时也用其复数形式 Cookies,指某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上的数据. 常见的用途就是保留用户登陆信息,登陆时的7天免登陆,记住 ...
- Spring MVC和Spring Data JPA之获取数据表数据放在List集合,显示在JSP页面
涉及到很多xml配置没写:只写具体实现的所有类 1.实体类 对应数据表SYS_SBGL, 主键是SBBM,主键是自动生成的uuid 数据表内容如下(有图有真相): package com.jinhet ...
- Jena解析rdf、nt、ttl格式数据
比如有一个ttl格式的文件名为cco.ttl package com.jena; import java.io.InputStream; import com.hp.hpl.jena.rdf.mode ...
- LINK : fatal error LNK1123
转: LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 这个是由于日志文件引起的,可以将 项目\属性\配置属性\清单工具\输入和输出\嵌入清单:原来 ...
- 踢掉某个li
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- beta阶段贡献分配实施
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2281] 要求1 每位组员的贡献分值 刘莹莹 王玉潘 潘世维 周昊 赵美增 ...