2017-03-27 15 views
0

こんにちは、私はJavaのスプリングアプリケーションで、私は2回実行する私の残りのコントローラを呼び出すときに問題があります。Spring MVC double initialize

これは

@Controller 
public class CrashReportController extends AbstractBaseController { 

private final Logger logger = LoggerFactory.getLogger(CrashReportController.class); 

private CrashReportRequest crashReportRequest; 


@Override 
protected Logger getLogger() { 
    return logger; 
} 

@RequestMapping(value = "/req/{token}", method = RequestMethod.POST, consumes = "application/json", produces = "application/pdf") 
public @ResponseBody ResponseEntity<byte[]> req(@RequestBody CrashReportRequest request, @PathVariable ("token") String token) 
     throws IOException {...} 

}

これは私のweb.xmlで私のコントローラである:

<?xml version="1.0" encoding="ISO-8859-1"?>  

<display-name>rmp</display-name> 


<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>resources/app-config.xml</param-value> 
</context-param> 

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

<servlet> 
    <servlet-name>my-dispatcher-servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>resources/web-config.xml</param-value> 
    </init-param>  
</servlet> 

<servlet-mapping> 
    <servlet-name>my-dispatcher-servlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

のApp-config.xmlの

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="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 "> 


<context:component-scan base-package="rmp.rest.controller"> 
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
</context:component-scan> 

のWeb-config設定

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://www.springframework.org/schema/mvc 
         http://www.springframework.org/schema/mvc/spring-mvc.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context.xsd "> 

<context:component-scan base-package="rmp.rest.controller"> 
    <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
</context:component-scan> 

<mvc:resources mapping="/resources/**" location="/resources/" /> 
<mvc:annotation-driven /> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/view/"/> 
     <property name="suffix" value=".jsp"/> 
</bean> 

私は(私はこれが問題であると仮定)ダブルinitilizeを持っているのはなぜ? 私はこれを解決するために夢中ですよ、助けてください!

答えて

0

"rmp.rest.controller"パッケージを2回スキャンします(したがって、その上のすべてのBeanを2回初期化します)。

これは、次の要素によって発生します。

<context:component-scan base-package="rmp.rest.controller"> 
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
</context:component-scan> 

とWeb-config.xmlの:のApp-config.xmlでのApp-config.xmlに前の要素を削除する

<context:component-scan base-package="rmp.rest.controller"> 
    <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
</context:component-scan> 

フォローするパスがそうです。

+0

ありがとうAndres、だから私は何を変えなければなりませんか? App-config? Web-config? – Michele

+0

@Micheleは私の編集を参照してください – Andres

+0

私はコンテキストを完全に削除しました:App-configからのcomponent-scanタグですが、まだ2回実行されます。私は非常に失望し、すべてを試しました... – Michele