0

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 ?

Gurubg
  • 73
  • 7
  • Have you included package of GreetingController class in componentScan? – Oomph Fortuity Nov 28 '17 at 11:03
  • I added @ComponentScan(basePackages = { "com.abc.sos" }) to TestController class , but it still throws the same exception. – Gurubg Nov 28 '17 at 11:18
  • Looks like you haven't added that jar file to Tomcat's ClassPath. – Yoory N. Nov 28 '17 at 13:16
  • Don't use `system` scope... See https://stackoverflow.com/questions/10935135/maven-and-adding-jars-to-system-scope and https://stackoverflow.com/questions/16907682/whats-the-difference-between-these-maven-dependency-scopes-provided-compile-sy – M. Deinum Nov 28 '17 at 14:24

0 Answers0