2017-02-05 4 views
0

私はスプリングのセキュリティを学んでいるので、私は下の最初の例を試していた、それは私に404エラーを与えています。春のセキュリティは、404を与えるページをロードしていません

package com.security.test; 

import java.io.IOException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

@WebServlet(urlPatterns = { "/hello" }) 
public class HelloWorldServlet extends HttpServlet { 
    private static final long serialVersionUID = 2218168052197231866L; 

    @Override 
    public void doGet(HttpServletRequest request, HttpServletResponse response) { 
     try { 
      response.getWriter().write("Hello World"); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

ここにすべてはそれが404何も存在していない私を与える代わりに、ハロー世界の、私がログインしたときを除き、罰金行くを次のように私は、サーブレットを持っている上

その後
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:security="http://www.springframework.org/schema/security" 
    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.1.xsd"> 
    <security:http auto-config="true"> 
     <security:intercept-url pattern="/hello" 
      access="ROLE_SCARVAREZ_MEMBER" /> 
    </security:http> 
    <security:authentication-manager> 
     <security:authentication-provider> 
      <security:user-service> 
       <security:user authorities="ROLE_SCARVAREZ_MEMBER" 
        name="car" password="scarvarez" /> 
       <security:user authorities="ROLE_SCARVAREZ_MEMBER" 
        name="mon" password="scarvarez" /> 
       <security:user authorities="ROLE_SCARVAREZ_MEMBER" 
        name="bea" password="scarvarez" /> 
       <security:user authorities="ROLE_SCARVAREZ_MEMBER" 
        name="andr" password="scarvarez" /> 
      </security:user-service> 
     </security:authentication-provider> 
    </security:authentication-manager> 
</beans> 

以下のセキュリティ設定ファイルを見つけてください。そのようなtomcatコンソールに。これに問題があるかどうかを知りたかっただけですか?

編集: - あなたはHttpServletのが、春を使用する必要はありません春のセキュリティを使用していると私のweb.xmlファイル

<web-app> 
<listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
</listener> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext-security.xml 
    </param-value> 
</context-param> 
    <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> 
+1

なぜSpringで 'HttpServlet'を使用していますか? – Andremoniy

+0

私が呼んだのは '/ hello' URLです。呼び出してログインし成功した後の同じURLです。Hello World – Nilesh

+0

@Andremoniy:@Controllerも使用できますが、これは問題になりますか? – Nilesh

答えて

-1

を見つけてください。

次に、スプ​​リングの設定XMLファイルを作成し、コントローラクラスをマッピングするための@Controller "と"/hello "の" @RequestMapping "としてアノテーションを使用します。

私はコメントしますが、私はまだできません。

関連する問題