Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用多个dispatcher servlet和maven覆盖进行Spring MVC上下文扫描_Spring_Maven_Spring Mvc_Servlets - Fatal编程技术网

使用多个dispatcher servlet和maven覆盖进行Spring MVC上下文扫描

使用多个dispatcher servlet和maven覆盖进行Spring MVC上下文扫描,spring,maven,spring-mvc,servlets,Spring,Maven,Spring Mvc,Servlets,我正在用spring构建一个模块化的web应用程序,使用maven overlays在一个主web应用程序上组合不同的模块。这两个应用程序都是标准的maven原型webapp结构。为了进行测试,我创建了一个名为“门户”的项目,它将成为主战,以及一个覆盖在主战上的“hello”项目。主要档案包括: 门户(主)应用程序 web.xml: 另一个在主项目(门户)上: 主pom.xml(在门户上) 我正在使用Widfly 9.0.2和Spring 4.2,最终通过重新安装WildFly解决了这个问题。上

我正在用spring构建一个模块化的web应用程序,使用maven overlays在一个主web应用程序上组合不同的模块。这两个应用程序都是标准的maven原型webapp结构。为了进行测试,我创建了一个名为“门户”的项目,它将成为主战,以及一个覆盖在主战上的“hello”项目。主要档案包括:

门户(主)应用程序 web.xml:

另一个在主项目(门户)上:

主pom.xml(在门户上)


我正在使用Widfly 9.0.2和Spring 4.2,最终通过重新安装WildFly解决了这个问题。上述配置适用于多个dispatcher servlet,maven将多个web项目组合到一个可部署的war中。

最终,通过重新安装WildFly解决了此问题。上面的配置适用于多个dispatcher servlet,maven将多个web项目组合成一个可部署的war。

为什么说在组件扫描期间不选择控制器?您是否尝试点击控制器的URL。您的配置看起来很好,我在日志中缺少了“Path/hello/…mapped to servlet x.y.x.”这些行,它们在迁移projecto以获得多个dispatcher servlet解决方案之前出现并工作。更准确地说,我希望这些行:[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](ServerService线程池--6)将“{[/portal/],methods=[GET]}”映射到公共org.springframework.web.servlet.ModelAndView pt.fhc.fmc.web.controllers.HomeController.home2(java.util.Locale)要解决由于打包结构导致无法扫描的问题,请在配置文件中手动注册您的bean并查看其是否有效。为什么说在组件扫描期间未拾取控制器?您是否尝试点击控制器的URL。您的配置看起来很好我在日志中丢失了这些行“Path/hello/…mapped to servlet x.y.x.”在迁移projecto以获得多dispatcher servlet解决方案之前出现并工作。更准确地说,我期待以下几行:[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](ServerService线程池--6)映射“{[/portal/],methods=[GET]}“在public org.springframework.web.servlet.ModelAndView pt.fhc.fmc.web.controllers.HomeController.home2(java.util.Locale)上进行故障排除,如果由于打包结构导致扫描失败,请在配置文件中手动注册bean,并查看其是否有效。”。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>fmc</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/application-context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>main</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>main</servlet-name>
        <url-pattern>/portal</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/module-hello</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd     
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:application.properties</value>
        </property>
    </bean>
    <mvc:annotation-driven />
    <tx:annotation-driven transaction-manager="txManager" />
    <context:component-scan base-package="pt.fhc.fmc.services" />
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages">
        </property>
        <property name="defaultEncoding" value="UTF-8">
        </property>
    </bean>
    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang">
        </property>
    </bean>
    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="pt">
        </property>
    </bean>
    <bean id="handlerMapping"
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="1" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd     
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
    <mvc:annotation-driven />
    <context:component-scan base-package="pt.fhc.fmc.web" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd     
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="pt.fhc.fmc.modules.hello" ></context:component-scan>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
package pt.fhc.fmc.modules.hello;
// Standard spring imports.

@Controller
public class HelloController {

    @Autowired
    TestService testService;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView home(Locale locale) {

        ModelAndView model = new ModelAndView("helloview");
        return model;
    }
}
package pt.fhc.fmc.web.controllers;

@Controller
public class HomeController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView  home(Locale locale) {

        ModelAndView model = new ModelAndView("home");
        return model;
    }
}
    <dependencies>
        <dependency>
            <groupId>pt.fhc.fmc</groupId>
            <artifactId>portal.services</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Modules -->
        <dependency>
            <groupId>pt.fhc.fms.modules</groupId>
            <artifactId>module-hello</artifactId>
            <type>war</type>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>

                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>pt.fhc.fms.modules</groupId>
                            <artifactId>module-hello</artifactId>
                        </overlay>
                    </overlays>
                </configuration>

            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
16:00:42,908 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 100) Initializing Spring root WebApplicationContext
16:00:42,908 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 100) Root WebApplicationContext: initialization started
16:00:42,981 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 100) Refreshing Root WebApplicationContext: startup date [Fri Mar 11 16:00:42 GMT 2016]; root of context hierarchy
16:00:43,016 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 100) Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/application-context.xml]
16:00:43,207 INFO  [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] (ServerService Thread Pool -- 100) Loading properties file from class path resource [application.properties]
16:00:43,211 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 100) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
16:00:43,396 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Mar 11 16:00:42 GMT 2016]; root of context hierarchy
16:00:43,435 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Mar 11 16:00:42 GMT 2016]; root of context hierarchy
16:00:43,513 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 100) Root WebApplicationContext: initialization completed in 604 ms
16:00:43,517 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 100) Initializing Mojarra 2.2.12-jbossorg-2 20150729-1131 for context '/fmc'
16:00:43,964 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 100) Initializing Spring FrameworkServlet 'main'
16:00:43,964 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 100) FrameworkServlet 'main': initialization started
16:00:43,967 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 100) Refreshing WebApplicationContext for namespace 'main-servlet': startup date [Fri Mar 11 16:00:43 GMT 2016]; parent: Root WebApplicationContext
16:00:43,967 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 100) Loading XML bean definitions from ServletContext resource [/WEB-INF/main-servlet.xml]
16:00:44,001 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 100) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
16:00:44,032 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: WebApplicationContext for namespace 'main-servlet': startup date [Fri Mar 11 16:00:43 GMT 2016]; parent: Root WebApplicationContext
16:00:44,046 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: WebApplicationContext for namespace 'main-servlet': startup date [Fri Mar 11 16:00:43 GMT 2016]; parent: Root WebApplicationContext
16:00:44,099 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 100) FrameworkServlet 'main': initialization completed in 135 ms
16:00:44,100 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 100) Initializing Spring FrameworkServlet 'hello'
16:00:44,100 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 100) FrameworkServlet 'hello': initialization started
16:00:44,101 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 100) Refreshing WebApplicationContext for namespace 'hello-servlet': startup date [Fri Mar 11 16:00:44 GMT 2016]; parent: Root WebApplicationContext
16:00:44,103 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 100) Loading XML bean definitions from ServletContext resource [/WEB-INF/hello-servlet.xml]
16:00:44,131 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 100) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
16:00:44,160 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: WebApplicationContext for namespace 'hello-servlet': startup date [Fri Mar 11 16:00:44 GMT 2016]; parent: Root WebApplicationContext
16:00:44,173 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 100) Looking for @ControllerAdvice: WebApplicationContext for namespace 'hello-servlet': startup date [Fri Mar 11 16:00:44 GMT 2016]; parent: Root WebApplicationContext
16:00:44,205 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 100) FrameworkServlet 'hello': initialization completed in 105 ms
16:00:44,205 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 100) WFLYUT0021: Registered web context: /fmc
16:00:44,411 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "portal.web.war" with deployment "portal.web.war"