springboot:注解

@EnableAutoConfiguration注解
exclude 排除属性来禁用
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
===============================================
这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring
如spring-boot-starter-web 添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用并相应地对Spring进行设置。Spring Boot将仍旧尽最大努力去自动配置你的应用。
===============================================
@Configuration
===============================================

===============================================
@ComponentScan
===============================================
@ComponentScan 注解搜索beans,并结合 @Autowired 构造器注入
添加 @ComponentScan 注解而不需要任何参数。你的所有应用程序组件( @Component , @Service , @Repository , @Controller 等)将被自动注册为Spring Beans
===============================================
@SpringBootApplication
===============================================
@SpringBootApplication 注解等价于以默认属性使用 @Configuration , @EnableAutoConfiguration 和 @ComponentScan

===============================================
@ConfigurationProperties
===============================================
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {}

@Autowired
private ConnectionSettings connection

===============================================
@EnableConfigurationProperties
===============================================
当@EnableConfigurationProperties注解应用到你的@Configuration时,任何被@ConfigurationProperties注解的beans将自动被Environment属性配置

@ConfigurationProperties(ConnectionSettings.class)
public class Settings {
}
//会自动注入带有注释ConfigurationProperties的类
@EnableConfigurationProperties({Settings.class})
public class Application{
        @Autowired
        Settings configationSettings;
}
===============================================
@Profiles
spring.profiles.active=
===============================================
@Configuration
@Profile("test")
public class TestConfiguration {}

<logger name="org.spring.springboot" level="DEBUG" additivity="false">
        <appender-ref ref="APP"/>
       
        <springProfile name="dev">
            <appender-ref ref="CONSOLE"/>
        </springProfile>
       

</logger>
===============================================
@ExceptionHandler
全局拦截
===============================================
@ExceptionHandler({UnauthenticatedException.class, AuthenticationException.class})
    @ResponseBody
    public Map<String, Object> authenticationException(HttpServletRequest request, HttpServletResponse response) {
        // 输出JSON
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "-999");
        map.put("message", "未登录");
        return map;
    }

猜你喜欢

转载自samson870830.iteye.com/blog/2382702