I want to extend a class which contains rest APIs (jar) in another project (war).
I have a jar file which has defined a rest api using @restcontroller . For example ,
@RestController
public class GreetingController {
private static final String template = "Hello!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
I am trying to extend this class in another project which is packaged as a war file and will be deployed in tomcat server.
@RestController
//@Controller
@RequestMapping("/")
public class TestController extends GreetingController {
private static final String template = "Hello1, s!";
//private final AtomicLong counter = new AtomicLong();
@RequestMapping("/hello")
public String hello() {
return template;
}
}
I have included the jar as external source in maven
<dependency>
<groupId>com.iot</groupId>
<artifactId>gs-rest-service</artifactId>
<scope>system</scope>
<version>0.1.0</version>
<systemPath>D:\workspace\gs-rest-service-complete\target\gs-rest-service-0.1.0.jar</systemPath>
</dependency>
When I run deploy this war file to tomcat , it throws the following error.
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.abc.controllers.TestController; nested exception is java.io.FileNotFoundException: class path resource [com/abc/sos/GreetingController.class] cannot be opened because it does not exist
class path resource [com/abc/sos/GreetingController.class] cannot be opened because it does not exist
Is there a problem with annotation ? looks like the classes of jar file are not linked during the run time. Can any one point out the problem with this approach ?