servlet 3.0 - Spring web fragments and java config -


i created simple spring-mvc web app (one controller), , simple spring jar (containing 1 controller).

i utilized servlet 3 spec using web fragments, came across that, if using spring xml configuration (as per example spring-mvc project created in sts), controller in jar not being called or hit when entered url, if used java config worked fine.

and java config did import xml , set scanning... i'm curious why was, got ideas?

java config:

@enablewebmvc @configuration @componentscan(basepackages = { "com.webapp.test" }) @importresource({"classpath:webapp-context.xml"}) public class testconfig  extends webmvcconfigureradapter {  } 

webapp-context.xml

<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:beans="http://www.springframework.org/schema/beans"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">      <!-- dispatcherservlet context: defines servlet's request-processing infrastructure -->      <!-- enables spring mvc @controller programming model -->     <annotation-driven />      <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory -->     <resources mapping="/resources/**" location="/resources/, classpath:/meta-inf/resources/" />      <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory -->     <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver">         <beans:property name="prefix" value="/web-inf/views/" />         <beans:property name="suffix" value=".jsp" />     </beans:bean>                 </beans:beans> 

my web-fragment.xml

   <web-fragment xmlns="http://java.sun.com/xml/ns/javaee"                   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"                   xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"                   version="3.0">          <!-- definition of root spring container shared servlets , filters -->         <context-param>             <param-name>contextconfiglocation</param-name>             <param-value>classpath*:/meta-inf/web-fragment-context.xml</param-value>         </context-param>      <!-- creates spring container shared servlets , filters -->     <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>       </web-fragment> 

web-fragment-context.xml

<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:beans="http://www.springframework.org/schema/beans"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">      <!-- dispatcherservlet context: defines servlet's request-processing infrastructure -->      <!-- enables spring mvc @controller programming model -->     <annotation-driven />      <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory-->      <resources mapping="/resources/**" location="classpath:/meta-inf/resources/" />      <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory -->     <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver">         <beans:property name="prefix" value="/web-inf/views/" />         <beans:property name="suffix" value=".jsp" />     </beans:bean>      <context:component-scan base-package="com.fragment.tests" />   </beans:beans> 

my web.xml in main webapp

<web-app metadata-complete="false" xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"     version="3.0">      <servlet>         <servlet-name>appservlet</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <!-- configure dispatcherservlet use javaconfigwebapplicationcontext              instead of default xmlwebapplicationcontext -->         <init-param>             <param-name>contextclass</param-name>             <param-value>             org.springframework.web.context.support.annotationconfigwebapplicationcontext          </param-value>         </init-param>         <!-- again, config locations must consist of 1 or more comma- or space-delimited              , fully-qualified @configuration classes -->         <init-param>             <param-name>contextconfiglocation</param-name>             <param-value>com.fragments.test.contextconfiguration</param-value>         </init-param>     </servlet>      <servlet-mapping>         <servlet-name>appservlet</servlet-name>         <url-pattern>/</url-pattern>     </servlet-mapping> </web-app> 


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -