1

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";}
}
Amit
  • 451
  • 1
  • 6
  • 19
  • how about show us your actual code. might it be you've forgotten to add a bean of type 'service.ApiCaller'? my advice, drop the random tutorials and have a look at this: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/ – Stultuske Feb 20 '18 at 08:03
  • As far I understand from the custom starter. After adding dependency I should be able to use in the app as `@Autowired private ApiCaller fooApiCaller;` , as like here https://github.com/eugenp/tutorials/blob/master/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/java/com/baeldung/greeter/sample/GreeterSampleApplication.java – Amit Feb 20 '18 at 08:06
  • the springboot reference never mentions an ApiCaller type. it is most likely a Type you still have to create – Stultuske Feb 20 '18 at 08:08
  • `ApiCaller` is my class name which is supposed to be used by the app. It is something like `Greeter` class mentioned in the example above. – Amit Feb 20 '18 at 08:10
  • 1
    there is no 'Greeter class', there is no 'example above'. post your own code, not a link to something that 'might look similar'. how did you configure your bean? – Stultuske Feb 20 '18 at 08:12

0 Answers0