0

Hy folks. I am getting issue in multi module project. My project have 3 jar modules and 1 web module.

ABZ
ABZ-service
ABZ-dao
ABZ-webapp

in this 'ABZ' is my parent module and 'ABZ-webapp' is my web module. All request are being treated through spring container. BUT now i want to add new module for web services spring REST web service. In which I would like to have REst controllers.

ABZ-webservice

My question here is, what should I do so that my context would scan packaging structure of 'ABZ-webservice' module. FYI..ABZ-webservice .

web.xml

<servlet>
    <servlet-name>ABZ</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
        <servlet-name>ABZ</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

spring-context.xml

<context:component-scan base-package="com.ABZ.rest.controller" />
<context:component-scan base-package="com.ABZ.web.controller" />

<bean id="templateResolver"
        class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".html" />
        <property name="templateMode" value="HTML5" />
        <!-- Template cache is set to false (default is true). -->
        <property name="cacheable" value="false" />
        <property name="characterEncoding" value="UTF-8" />

    </bean>

NormalController in ABZ-webapp module

package com.ABZ.web.controller;
@controller
@RequestMappig (--)
public class NormalController{

   @RequestMappig (--)
  public String test()
  {
  }
}

RestController in ABZ-webservice module

package com.ABZ.rest.controller;
@controller
@RequestMappig (--)
public class RestController{

   @RequestMappig (--)
  public String test()
  {
  }
}

contextPath: localhost:8080/ABZ-webapp/

NormalController is being accessible but not RestController now from this controller path I want to hit URL which is in my 'ABZ-webservice' module

erhun
  • 3,549
  • 2
  • 35
  • 44
user3029929
  • 471
  • 2
  • 7
  • 20

1 Answers1

0

You already define your component-scan at spring-context.xml they are OK

<context:component-scan base-package="com.ABZ.rest.controller" />
<context:component-scan base-package="com.ABZ.web.controller" />

Now Define your classes as

NormalController in ABZ-webapp module

package com.ABZ.web.controller;
@controller
@RequestMappig (value="/web")
public class NormalController{

   @RequestMappig (value="/test")
  public String test()
  {
  }
}

RestController in ABZ-webservice module

package com.ABZ.rest.controller;
@controller
@RequestMappig (value="/rest")
public class RestController{

   @RequestMappig (value="/test")
  public String test()
  {
  }
}

And make your test like

http://localhost:8080/webAppName/web/test

and

http://localhost:8080/webAppName/rest/test

If you have any question, i can edit my answer.

erhun
  • 3,549
  • 2
  • 35
  • 44