Question

Basically I have a multi module application:

data business web-app

in the web-app part there is web.xml with this configuration for loading different applicationContext.xml configuration files:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/applicationContext.xml</param-value>
</context-param>

[...]

<!-- Handles Spring requests -->
<servlet>
    <servlet-name>empp-v2-web</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/spring/webmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

my other two modules have each an META-INF/spring/applicationContext.xml. in webmvc-config.xml I do a component scan only for classes with @Controller annotation, meanwhile in the applicationContext I scan for everything in the base package except controllers.

the problem is that when I try to autowire a bean in a controller I get always a NoSuchBeanDefinitionException. This happens running the application as an exploded project with "Add and Remove" on the server configured in eclipse. If I do a maven build and deploy manually the application on the same server, the application works and the beans are autowired. Does m2eclipse need some special configuration? To me it seems that the applicationContext.xml are not loaded in this case. How can verify that m2eclipse is coping resource files in the correct place?

Was it helpful?

Solution

Seems there is some issue with m2eclipse and loading multiple application-context in the classpath. The only solution for me was to put everything spring configuration inside the main web application application-context. This solution solution works both in a packaged EAR and also as exploded application run inside eclipse.

OTHER TIPS

Have you installed m2e-wtp? On what server are you deploying to? You should diff the contents of the exploded war deployed via WTP vs the contents of the war archive, see if something's missing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top