Which beans are started by the springboot application

  • 的头像-Tumi
  • 16 day agopublish

Ben Pian Wen Zhang Wei Da Jia Zhan Shi Liao Springboot Ying Yong Dao Di Qi Dong Liao Na Xie bean, Nei Rong Jian Ming E Yao Bing Qie Rong Yi Li Jie , Jue Dui Neng Shi Ni Yan Qian Yi Liang , Tong Guo Zhe Pian Wen Zhang De Xiang Xi Jie Shao Xi Wang Ni Neng You Suo Shou Huo 。

1. Gai Shu

Wo Men Jiang Tan Suo Zai Rong Qi Zhong Huo Qu Suo You spring Guan Li De bean De Xiang Guan Ji Shu 。 Zhe You Shen Ma Yong ? Zhu Yao Shi Yong Yu Pai Cha Wen Ti 。 Yi Ban Du Shi Wo Men Chuang Jian De Mou Yi Ge bean Mei You Qi Dong De Wen Ti 。 Bi Jing Gong Zuo Zhong Zong Shi Hui Yu Dao Ge Zhong Ge Yang De bug。 Ti Qian Liao Jie Yi Xie Mei You Huai Chu 。

2. IoC Rong Qi

bean Shi spring Guan Li De Ying Yong Cheng Xu De Ji Chu , Suo You bean Du Zhu Liu Zai IOC Rong Qi Zhong , Gai Rong Qi Fu Ze Guan Li Ta Men De Sheng Ming Zhou Qi 。

Wo Men Ke Yi Tong Guo Liang Zhong Fang Shi Huo Qu Gai Rong Qi Nei Suo You bean De Lie Biao :

  • Shi Yong ListableBeanFactory Jie Kou

  • Shi Yong Spring Boot Actuator

3. Shi Yong ListableBeanFactory Jie Kou

ListableBeanFactory Jie Kou Ti Gong Liao getBeanDefinitionNames() Fang Fa , Gai Fang Fa Fan Hui Zai Zhe Ge Gong Chang Zhong Ding Yi De Suo You bean De Ming Cheng 。 Nin Ke Yi Zai Guan Fang Wen Dang Zhong Zhao Dao Suo You Yi Zhi Zi Jie Kou Ji Qi Shi Xian Lei De Lie Biao 。 Wo Men Lai Kan Zhe Zhong Fang Shi Ru He Huo Qu Suo You De bean。

Di Yi Bu : Chuang Jian Yi Ge Controller

@Controller public class FooController {     @Autowired     private FooService fooService;     @RequestMapping(value="/displayallbeans")     public String getHeaderAndBody(Map model){         model.put("header", fooService.getHeader());         model.put("message", fooService.getBody());         return "displayallbeans";     } }

Zhe Ge Controller Yi Lai Yu Ling Yi Ge FooService。

Di Er Bu : Chuang Jian Service

@Service public class FooService {     public String getHeader() {         return "Display All Beans";     }     public String getBody() {         return " Zhan  Shi  Suo  You beans De  An  Li ";     } }

Zhu Yi , Wo Men Zai Zhe Li Chuang Jian Liao Liang Ge Bu Tong De bean:

  • fooController

  • fooService

Zhe Li Shi Yong applicationContext Dui Xiang Bing Diao Yong Ta De getBeanDefinitionNames() Fang Fa , Gai Fang Fa Jiang Fan Hui applicationContext Rong Qi Zhong De Suo You bean:

Di San Bu : She Zhi SpringBootApplication Qi Dong Lei

@SpringBootApplication public class DemoApplication {     private static ApplicationContext applicationContext;     public static void main(String[] args) {         applicationContext = SpringApplication.run(DemoApplication.class, args);         displayAllBeans();     }     public static void displayAllBeans() {         String[] allBeanNames = applicationContext.getBeanDefinitionNames();         for(String beanName : allBeanNames) {             System.out.println(beanName);         }     } }

Di Si Bu : Ce Shi Da Yin

Zhe Jiang Da Yin applicationContext Rong Qi Zhong De Suo You bean:

Springboot Ying  Yong  Dao  Di  Qi  Dong  Liao  Na  Xie bean

Zhu Yi , Chu Liao Wo Men Ding Yi De bean Zhi Wai , Ta Huan Jiang Ji Lu Gai Rong Qi Zhong De Suo You Qi Ta bean。 Wei Liao Qing Chu Qi Jian , Wo Men Zai Zhe Li Sheng Lue Liao Ta Men , Yin Wei Ta Men You Hen Duo 。

4. Shi Yong Spring Boot Actuator

Spring Boot Actuator Ti Gong Liao Yong Yu Jian Kong Ying Yong Cheng Xu Tong Ji Xin Xi De Duan Dian 。 Xia Mian Kan Kan Zhe Zhong Fang Shi :

Di Yi Bu : Tian Jia Yi Lai

<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-actuator</artifactId> </dependency>

Di Er Bu : Xiu Gai application.properties

management.endpoints.web.exposure.include=*

Ba Shang Mian Dai Ma Tian Jia Dao properties Wen Jian Zhong 。

Di San Bu : Shi Yong Fa Bu Duan Dian Cha Kan

Springboot Ying  Yong  Dao  Di  Qi  Dong  Liao  Na  Xie bean

You Yu Zhe Li De Actuator Mei You Pei Zhi , Suo Yi Xian Shi De Bi Jiao Luan 。

Shang Shu Nei Rong Jiu Shi Springboot Ying Yong Dao Di Qi Dong Liao Na Xie bean, Ni Men Xue Dao Zhi Shi Huo Ji Neng Liao Ma ? Ru Guo Huan Xiang Xue Dao Geng Duo Ji Neng Huo Zhe Feng Fu Zi Ji De Zhi Shi Chu Bei , Huan Ying Guan Zhu Tumi Yun Xing Ye Zi Xun Pin Dao 。

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment