Spring boot custom starter , application doesn't find required bean

。_饼干妹妹 提交于 2019-12-24 09:00:00

问题


http://www.baeldung.com/spring-boot-custom-starter

I have followed tutorial and github example provided from the link above and have implemented similar way. I am using spring-boot-starter-parent :2.0.0.M3. Even after including my custom starter dependency in the pom for the app, it doesn't find required bean without @componentScan while deploying it.

It is giving following error.


APPLICATION FAILED TO START


Description:

Field fooApiCaller in com.core.controller.TestController required a bean of type 'service.ApiCaller' that could not be found.

Action:

Consider defining a bean of type 'service.ApiCaller' in your configuration.

Sample App ( one throwing error) pom.xml

<dependency>
        <groupId>abc.def</groupId>
        <artifactId>custom-starter</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
@Controller
public class FooController {
@Autowired
ApiCaller fooApiCaller
}

custom-starter module pom.xml

<dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <dependency>
            <groupId>abc.def</groupId>
            <artifactId>custom-spring-boot-autoconfigure</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>abc.def</groupId>
            <artifactId>myapi</artifactId>
            <version>${project.version}</version>
        </dependency>

    </dependencies>

Autoconfiguration module dependency

 <dependencies>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
                <version>${spring-boot.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
                <version>${spring-boot.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <version>${spring-boot.version}</version>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>abc.def</groupId>
                <artifactId>myapi</artifactId>
                <version>${project.version}</version>
                <optional>true</optional>
            </dependency>

        </dependencies>

spring factories code

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
abc.def.myapi.autoconfigure.AutoConfiguration

MyAPI product

@Service
@Configuration
public class ApiCaller {

public String getName(String Id){return "name";}
}

来源:https://stackoverflow.com/questions/48880240/spring-boot-custom-starter-application-doesnt-find-required-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!