Search code examples
javaspringspring-bootspring-restcontroller

RestController autowire interface nosuchbeandefinition


I wrote an application using spring-boot 1.5.10 RELEASE. I need to autowire interface which I will be use as WebService. I have got configuration class:

package com.app.packA;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class StartWebApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
    SpringApplication.run(StartWebApplication.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(StartWebApplication.class);
}

}

My RestController:

package com.app.packA;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

@Autowired
CalculatorWs calcService;

}

and interface from another package

package com.app.packB;

@WebService(name="CalculatorService")
public interface CalculatorWs {

public int sum();

public int multiply();
}

When I try to start this application on Tomcat 7, I received message that In "GreetingController" NoSuchBeanDefinition "CalculatorWs"


Solution

  • use @Service instead of @WebService