I got a REALLY simple project:
dispatcher xml:Code:<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.1.1.RELEASE</version> </dependency>
applicationcontext xml:Code:<context:component-scan base-package="be.wim.controller" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/"/> <property name="suffix" value=".jsp"/> </bean>
With this web.xml:Code:<context:component-scan base-package="be.wim.service" />
Nothing special. Everything works.Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/spring-config.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
Now - since the dispatcher context is a child of the main application context - why can't I move the component scan for the controllers to there? If it's not in the dispatcher servlet config, the dispatcherservlet does not know any controller...
And also: How come this works without <context:annotation-config /> or <mvc:annotation-driven /> ?
I made the controller with @Controller, and @RequestMapping ....


Reply With Quote