Spring MVCの注釈の設定の問題
-
26-09-2019 - |
質問
私は、私が追加したすべてのサーブレット用の新しい設定ファイルを必要としないように、私の春のMVCの構成を改善しようとしているが、私は問題に実行していますよ。私はこのチュートリアル使ってみましたA>の開始点として、私は、私は理解できないという問題に実行しています。
問題は、私は私のサーブレットにGETを行うとき、私は404エラーを取り戻すことです。ここに私の設定とコントローラからの代表的なJavaのスニペットがあります:
のweb.xmlます:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<display-name>SightLogix Coordination System</display-name>
<description>SightLogix Coordination System</description>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application-context.xml
/WEB-INF/application-security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/slcs/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application-context.xml
/WEB-INF/application-security.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
アプリケーションのcontext.xmlます:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-init-method="init" default-destroy-method="destroy">
<mvc:annotation-driven />
<context:component-scan base-package="top.level" />
</beans>
アプリケーションのsecurity.xmlます:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http>
<intercept-url pattern="/**" access="ROLE_MANAGER" requires-channel="https" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailsService">
<password-encoder hash="sha"/>
</authentication-provider>
</authentication-manager>
<beans:bean id="myUserDetailsService"
class="path.to.my.UserDetailsServiceImpl">
</beans:bean>
</beans:beans>
Controllerクラスのスニペット(多くの1、それらはすべて、本質的にこのようになり)ます:
@Controller
@RequestMapping("/foo.xml")
public class FooController
{
@RequestMapping(method=RequestMethod.GET)
public void handleGET(HttpServletRequest request, HttpServletResponse response) throws IOException
{
...
缶誰もが私が間違ってやっているものを私に教えて? ありがとう!
解決
ここの場所のうち唯一のことは、あなたが、ルートWebアプリケーションのコンテキストおよびのサーブレットコンテキストの両方に同じコンテキストの設定ファイルを使用したことです。これはほとんど悪い考えであることが保証され、そして奇妙な行動の多くになります。これは、よくあなたの問題の原因である可能性があります。
ContextLoaderListener
はcontextConfigLocation
の<context-param>
で構成されており、作成したルートWebApplicationContext
を管理します。
ServletDispatcherServlet
はcontextConfigLocation
の<init-param>
で構成され、作成しサーブレットWebApplicationContext
を管理している。
ルートWebApplicationContext
サーブレットAppContextをの親である、ルートWebApplicationContext
にすなわち任意の豆は、サーブレットWebApplicationContext
のもの豆に表示されます。
あなたの最初のステップは、これらの構成を分離することでなければなりません。正しい場所で正しい豆と(例えば、すべてのMVCのものは、サーブレットコンテキストに行かなければなりません)。 Doがのない二つの間のの株式Bean定義、それだけで混乱を取得および/または破損します。
他のヒント
これは直接あなたの質問に答えていませんが、私はいつも私が間違って何が起こっているかを把握することはできませんとき春にデバッグログを有効にすることが役に立ったと評価していました。
以下は、私は一般的に私のlogging.propertiesファイルで使用していることの2つです
org.springframework.beans.factory.support.level=FINEST
org.springframework.security.level=FINEST
は、万が一、あなたのコントローラで複数のGET RequestMapping
を持っていますか?以上1未満があると曖昧さが春があいまいGETマッピングのいずれかにマップされない特定の要求にそれらを解決するに存在する場合。