spring mvc설정으로 인한 controller-mapping error
764
작성한 질문수 22
spring mvc방식으로 구현해보고 있는데 권한 인증인 403에러는 잘뜹니다. 하지만 controller를 통해서 들어가면 404에러가 뜹니다. 관련되서 질문드립니다.
@RestController
public class AdminController {
@GetMapping("/admin")
public String admin() {
return "admin";
}
}
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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
">
<security:http auto-config="true" use-expressions="false">
<security:intercept-url pattern="/**" access="ROLE_ADMIN"/>
<security:form-login/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="{noop}1234" authorities="ROLE_ADMIN, ROLE_USER"/>
<security:user name="user" password="{noop}1234" authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<mvc:resources mapping="/jsp/**" location="/jsp/"></mvc:resources>
<context:annotation-config/>
<context:component-scan base-package="com.test"/>
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
<bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/context-spring.xml
</param-value>
</context-param>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/context-spring.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
접속 404오류 로그
DEBUG [FilterChainProxy] - Securing GET /admin
DEBUG [HttpSessionSecurityContextRepository] - Retrieved SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=admin, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_ADMIN, ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=B6D437E830FDEBF274A77AF35C51A114], Granted Authorities=[ROLE_ADMIN, ROLE_USER]]]
DEBUG [SecurityContextPersistenceFilter] - Set SecurityContextHolder to SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=admin, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_ADMIN, ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=B6D437E830FDEBF274A77AF35C51A114], Granted Authorities=[ROLE_ADMIN, ROLE_USER]]]
DEBUG [FilterSecurityInterceptor] - Authorized filter invocation [GET /admin] with attributes [ROLE_ADMIN]
DEBUG [FilterChainProxy] - Secured GET /admin
DEBUG [DispatcherServlet] - GET "/admin", parameters={}
DEBUG [SimpleUrlHandlerMapping] - Mapped to org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@8c32dc
DEBUG [DispatcherServlet] - Completed 404 NOT_FOUND
DEBUG [SecurityContextPersistenceFilter] - Cleared SecurityContextHolder to complete request
답변 2
0
음
해당 소스는 저의 강의 이전버전인 xml 방식으로 구성이 된 것이라 정확한 답변을 드리기가 어려울 것 같습니다.
주신 소스는 강의에서 설명하는 스프링 부트 기반이 아닌 점과 스프링 시큐리티 버전과의 호환성 등 여러 다양한 환경적인 요인이 있을 수 있기 때문에 강의의 주제와 좀 벗어나는 것 같습니다.
양해 부탁드립니다.
시큐리티 공부 버전 질문
0
181
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
189
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
183
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
260
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
242
1
파라미터값이 넘어가지 않습니다 ....
0
376
1
security filterChain 설정 질문이 있습니다.
0
334
1
소스 부분 질문 드립니다.
0
210
2
섹션4 7번 강의 문제가 있는거 같네요.
0
345
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
308
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
560
2
error , exception 이 잘 안됩니다.
0
286
2
thymeleaf tag 질문합니다.
0
198
2
버전업하면서 deprecated된 것들이 너무많아요
0
479
1
spring security 패치 관련
0
439
1
모바일을 사용할때 토큰말고 세션
0
857
2
DB 연동한 인가 부분에 대한 질문입니다!
0
265
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
309
1
Config 파일 생성 시 질문이 있습니다.
0
229
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
435
2
403 에러 뜹니다.
0
814
2
login_proc의 존재에 대한 간략한 설명입니다
0
277
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
288
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
192
1





