SpringBoot消失的Web.xml

Filter 过滤器作为web.xml中重要的一部分,有着相当高的出场率,SpringBoot会默认注册几个Filter ApplicationContextHeaderFilter CharacterEncodingFilter 如果添加了Security依赖的话会加入SpringSecurityFilterChain 如果加入Actuator依赖的话就会加入WebRequestTraceFilter 实现自己的Filter JavaConfig注册Bean 我们如果自己要实现自己的Filter的话,需要实现Filter并实现其中的方法 同时要利用JavaConfig的方法来配置,一般情况下需要编写@Bean注解的返回值为FilterRegistrationBean的方法来实现JavaBean的注册 具体实现如下 需要注意的是此方法需要在被@Configuration注解的配置类中 @WebFilter+@ServletComponentScan 如果觉得Java代码的方式比较繁琐的话可以采用注解方式注册Filter,具体实现方式是在Filter实现类加入@WebFilter注解 例如 然后在SpringBootApplication类上添加@ServletComponentScan Filter的注册原理 我们采用JavaConfig的形式实现了Filter的注册,通过向上追溯得知FilterRegistrationBean的层级结构如下 ServletContextInitializer RegistrationBean AbstractFilterRegistrationBean FilterRegistrationBean 经查阅SpringBoot文档发现针对ServletContextInitializer的描述如下 Interface used to configure a Servlet 3.0+ context programmatically. Unlike WebApplicationInitializer, classes that implement this interface (and do not implement WebApplicationInitializer) will not be detected by SpringServletContainerInitializer and hence will not be automatically bootstrapped by the Servlet container. This interface is primarily designed to allow ServletContextInitializers to be managed by Spring and not the Servlet container. ...

2019年3月19日 · 1 分钟 · 天边的星星

SpringBoot 学习网站收藏

Spring Boot加载配置文件 https://my.oschina.net/wangyuefive/blog/704615#h3_4 问题3:如何根据线上环境和线下环境加载不同的配置?如何加载多个配置文件? 1、Profiles: Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只能在特定的环境下生效。在配置文件中,用spring.profiles.active属性来指定特定环境的配置文件。在Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,比如: application-dev.properties:开发环境 application-test.properties:测试环境 application-prod.properties:生产环境 至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。例如: application.properties配置:spring.profiles.active = dev即指定application-dev.properties会被加载。 2、通过启动参数指定运行环境。 通过命令行启动: ` java -jar xxxxx.jar <span class="hljs-comment">--spring.profiles.active=prod。</span>` 上述指定为prod环境,则spring application会自动根据application-{profile}.properties的格式找到application-prod.properties文件加载。 3、加载多个自定义文件。 例如: ` spring.profiles.active = dev,database` 等于告诉Spring Boot加载application-dev.properties和application-database.properties文件,从而实现多个配置文件的加载。 四种读取properties文件的方式 http://www.imooc.com/article/18252 集成Mybatis http://www.imooc.com/article/15406 开启定时任务 http://www.imooc.com/article/15612 spring-boot上传文件MultiPartFile获取不到文件问题解决 http://blog.csdn.net/happy_cheng/article/details/54178392 Spring boot上传文件时MultipartFile为空问题 http://blog.csdn.net/tanga842428/article/details/72773773 spring boot默认日志配置,以及改用log4j日志配置学习使用排出多余的依赖 http://blog.csdn.net/yanweihpu/article/details/54139382 http://blog.csdn.net/loongshawn/article/details/50951329

2017年9月20日 · 1 分钟 · 天边的星星

spring-boot–使用thymeleaf模板

参考:http://blog.csdn.net/u014695188/article/details/52347318 参考:http://blog.csdn.net/u012706811/article/details/52185345 整体步骤: (1) 在pom.xml中引入thymeleaf; (2) 如何关闭thymeleaf缓存 (3) 编写模板文件.html Spring Boot默认就是使用thymeleaf模板引擎的,所以只需要在pom.xml加入依赖即可: «/span>dependency> «/span>groupId>org.springframework.boot</groupId> «/span>artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> Thymeleaf缓存在开发过程中,肯定是不行的,那么就要在开发的时候把缓存关闭,只需要在application.properties进行配置即可: [html] view plain copy ######################################################## ###THYMELEAF (ThymeleafAutoConfiguration) ######################################################## #spring.thymeleaf.prefix=classpath:/templates/ #spring.thymeleaf.suffix=.html #spring.thymeleaf.mode=HTML5 #spring.thymeleaf.encoding=UTF-8 # ;charset= is added #spring.thymeleaf.content-type=text/html # set to false for hot refresh spring.thymeleaf.cache=false 编写模板文件src/main/resouces/templates/helloHtml.html [html] view plain copy 编写访问路径(com.kfit.test.web.TemplateController): [html] view plain copy package com.kfit.test.web; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** 模板测试. @author Administrator */ @Controller publicclass TemplateController { /** ...

2017年9月19日 · 2 分钟 · 天边的星星