zoukankan      html  css  js  c++  java
  • 在测试自定义starter时,若出现无法找到helloservice的Bean的解决方法

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    @ConditionalOnWebApplication//web应用才生效
    @EnableConfigurationProperties(HelloProperties.class)
    @ConditionalOnClass(HelloService.class)
    public class HelloServiceAutoConfiguration {
        @Autowired
        HelloProperties helloProperties;
        @Bean
        public HelloService helloService(){
            HelloService service = new HelloService();
            service.setHelloProperties(helloProperties);
            return service;
        }
    }

    在方法helloService上加@Bean标签

  • 相关阅读:
    每日日报2021.5.14
    每日日报2021.5.13
    每日日报2021.5.12
    每日日报2021.5.11 冲刺第十天
    《梦断代码》读后感3
    每日日报2021.5.10 冲刺第九天
    《梦断代码》读后感2
    每日日报2021 5/23
    每日日报2021 5/22
    每日日报2021 5/21
  • 原文地址:https://www.cnblogs.com/jamers-rz/p/14080690.html
Copyright © 2011-2022 走看看