Spring boot项目推荐程序目录结构

使用@configuration注解配置类,如果配置类内容较多可以拆分为多个,在main class当中通过@componentScan指定扫面的路径,自动加载;也可以通过@import注解来引入configuration class;如果配置是以xml文件的形式导入,可以通过@importResource注解来加载xml配置文件。
使用自动配置
在使用@configuration注解的配置类上添加@SpringBootApplication或则@EnableAutoConfiguration注解,推荐只使用其中一个。
使用@EnableAutoConfiguration的exclude属性排除某个自动配置;如果当前的类没有在classpath当中,可以使用ExcludeName属性指定要排除的类的全权限定名;也可以通过使用spring.autoconfigure.exclude属性控制自动排除的类。

使用@SpringBootApplication注解相当于使用@EnableAutoConfiguration(使用自动注解)、@ComponentScan(使用组件在指定位置扫描@Component配置)、@Configuration(允许在上下文注册注册或导入额外配置)。例如如下两种等效使用方法:


开发者工具:Spring-boot-devtools,默认关闭cache,使更改可见无需重启;例如spring.thymeleaf.cache。

网友评论