EnableAutoConfiguration
Spring Boot 的核心注解SpringBootApplication引起的探究
星期二, 十二月 3rd, 2019 | JAVA-and-J2EE, spring-boot | 没有评论
Spring Boot 的核心注解SpringBootApplication引起的探究
1.Spring Boot 的核心注解是哪个?
先上一个工程的启动配置项看下:
项目比较老混杂了spring boot,dubbo,jersey注册等
package com.pomelolee.cms; import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; import com.pomelolee.boot.dubbo.annotation.EnableDubboProvider; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletProperties; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ImportResource; import org.springframework.util.ClassUtils; import java.util.HashSet; import java.util.Set; @EnableFeignClients @SpringBootApplication @EnableApolloConfig @EnableDiscoveryClient @EnableDubboProvider @ImportResource("classpath*:/META-INF/spring/spring-job.xml") public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } @Bean public ResourceConfig resourceConfig() { ResourceConfig resourceConfig = new ResourceConfig(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true); Set<beandefinition> beanDefinitionSet = scanner.findCandidateComponents("com.pomelolee.cms.service"); beanDefinitionSet.addAll(scanner.findCandidateComponents("com.pomelolee.cms.facade")); beanDefinitionSet.addAll(scanner.findCandidateComponents("com.pomelolee.cms.config")); Set<Class<?>> clazzSet = new HashSet<Class<?>>(); for (BeanDefinition beanDefinition : beanDefinitionSet) { clazzSet.add( ClassUtils.resolveClassName( beanDefinition.getBeanClassName(), resourceConfig.getClassLoader())); } resourceConfig.registerClasses(clazzSet); resourceConfig.property(ServletProperties.FILTER_FORWARD_ON_404, true); return resourceConfig; } } </beandefinition> |
@SpringBootApplication 注解,就是 Spring Boot 的核心注解。
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (85)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (186)
- linux (143)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 低代码 (1)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)