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";}
}