Warning starting the spring boot application

2019-08-24 01:30发布

问题:

I am trying to write a SpringBoot application. But when I am trying to access it using Postman, it shows Status as 404 and gives a warning on console:

WARN 6616 --- [nio-8080-exec-1] o.g.jersey.internal.inject.Providers
: A provider com.cognizant.insurance.controller.RestServiceController registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.cognizant.insurance.controller.RestServiceController will be ignored.

My Rest Controller is:

@Component
@Provider

@Controller
@RequestMapping(value="/api", produces="application/json")
public class RestServiceController {
    @Autowired
    private CordaRPCService cordaRPCService;
    @Value(value = "${node.PartyA.rpc.hostport}")
    private String nodeRpcHostAndPort;
    @Value(value = "${nodename}")
    private String nodeName;

    CordaRPCOps rpcService = null;

    String inDateFormat = "dd/MM/yyyy";

    PolicyState policy;

    @RequestMapping(value="/createpolicy", method=RequestMethod.GET)
    public String doTradeCreditPolicy() {

    return "Hello";

}

My project Structure:

Main File:

package com.cognizant.insurance;



@SpringBootApplication
@EnableScheduling
@EnableCaching
@ComponentScan("com.cognizant.insurance")

 public class Application extends SpringBootServletInitializer {

public static void main(final String[] args) {

    new Application()
    .configure(new SpringApplicationBuilder(Application.class))
    .run(args);
}

}

回答1:

Is there any special reason for you to use @Provider annotation? If not, try to remove it. Controller should work without this annotation.

The same is about @Component. This is a general-purpose stereotype annotation indicating that the class is a spring component. If you are using @Controller, you don't need this annotation.

You can read about differences between @Component and @Controller here.