[JAVA SPRING]세션 체크 관련 작업 중 Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]] 오류를 만나다.
세션이 끊겼을 때 로그인페이지로 보내기 위한 작업을 진행중이다.
vue.js를 사용중인데, axios 호출시 세션이 끊겼을 경우 서버사이드 컨트롤러 단으로 접근조차 하지 않았다.
그래서 프론트엔드쪽에서 해결할 문제임을 직감하고 axios 호출 후 오류가 발생할 때 로그인페이지로 이동하도록
this.$router.push(‘/login.do’) 처리를 하였다.
web.xml 파일에서 세션 만료 시간을 1분으로 변경 한 후 테스트 하였고 정상동작을 확인하였다.
그래도 뭔가 아쉬워 분명 백엔드코드로 처리할 수 있는 방법이 있을 것 같아 기술 검토를 하였다.
web.xml에 세션을 체크하는 필터 클래스를 하나 만들어 준 후 DoFilter를 오버라이드하여 세션 관련 체크 로직을 추가 후 세션이 없을 때 getRequestDispatcher()를 사용하여 포워드 해주면 되는 것 같아 시도를 해보기로 하였다.
세션 정보를 체크하기 위해 Filter 클래스를 하나 추가하였다.
web.xml에 필터 클래스 및 .do 로 끝나는 url는 모두 체크하도록 적용 후 아파치 톰켓 서버를 시작했는데
오류가 발생하였다.
<filter>
<filter-name>loginCheckFilter</filter-name>
<filter-class>패키지명.LoginCheckFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginCheckFilter</filter-name>
<url-pattern>.do</url-pattern>
</filter-mapping>
web.xml에서 설정된 스프링 시큐리티 필터 체인 때문일까?
<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>
여튼 내가 추가한 loginCheckFilter 필터와 필터맵핑 정보를 제거 후 서버를 재기동 하면 정상적으로 올라왔다.
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1239)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:758)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:694)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1700)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1690)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1247)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 6 more
4월 10, 2022 1:36:38 오전 org.apache.catalina.startup.Catalina start
심각: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.startup.Catalina.start(Catalina.java:694)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:758)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1247)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 11 more
테스트해보기 위해 구현한 LoginCheckFilter.class 코드는 다음과 같다.
@WebFilter("/LoginCheckFilter")
public class LoginCheckFilter implements Filter {
private list<String> whiteList;
/**
* Default constructor.
*/
public LoginCheckFilter() {
whiteList = new ArrayList<String>();
whiteList.add("/login.do");
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if(!whiteLIst.contains(req.getRequestURI())) {
//세션 체크 로직
HttpSEssion session = req.getSession();
//User 모델 혹은 MemberVo체크
if (session == null || session.getAttribute("userId") == null ))
{
request.getRequestDispatcher("/login.do").forward(request, response);
또는
res.sendRedirect("/login.do");
return;
}
}
// pass the request along the filter chain
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
String urls = config.getInitParameter("avoidUrls");
StringTokenizer token = new StringTokenizer(urls, ",");
urlList = new ArrayList();
while ( token.hasMoreTokens() )
{
urlList.add(token.nextToken());
}
}
}
[스프링 필터와 스피링시큐리티 정리 잘된 블로그]
스프링 필터와 스프링 시큐리티(Spring Security)의 동작 구조
– Develop OS : Windows10 Ent, 64bit – WEB/WAS Server : Tomcat v9.0 – DBMS : MySQL 5.7.29 for Linux (Docker) – Language : JAVA 1.8 (JDK 1.8) – Framwork : Spring 3.1.1 Release – Build Tool : Maven 3.6..
codevang.tistory.com
[해결방법]
1. 메이븐 저장소 문제이므로 Preferences > Maven > User Settings > Local Repository 경로의 모든 파일 삭제.
2. Servers > Tomcat > Clean & Clean Tomcat Work Directory
3. Menu > Project > Clean
4. Project Explorer > 프로젝트 우클릭 > Maven > Update Project 또는 프로젝트 클릭하고 Alt+F5
[REFERENCE]
- https://logical-code.tistory.com/8
- http://repacat.tistory.com/30
- https://loveiskey.tistory.com/81
- https://sarc.io/index.php/java/296-sessionfilter
- https://wiper2019.tistory.com/98
- https://velog.io/@sorzzzzy/Spring-Boot5-7.-%EB%A1%9C%EA%B7%B8%EC%9D%B8-%EC%B2%98%EB%A6%AC2-%ED%95%84%ED%84%B0-%EC%9D%B8%ED%84%B0%EC%85%89%ED%84%B0