흔하게 실수 할 수 있는 spring mybatis 에러

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener



만약 당신이 전자정부 프레임워크를 사용하거나 spring 프레임워크 mybatis를 사용하고 있으며


typealias를 매핑형식으로 sql-map-config.xml에서 관리를 하는데 새로운 쿼리를 추가 하거나

 

typealias를 추가 했는데 서버를 구동시키자 저런 흉악한 에러메세지를 뿜어낸다면 그리고 분명히


경로를 제대로 복사 하였는데도 해당 VO클래스를 찾지 못한다는 에러 메세지가 나타난다면 1개만 더 확인 해 보자.


<typeAlias type="egovframework.easyplatform.common.tree.TreeDataVO" alias="treeDataVO" /> 


<typeAlias type="egovframework.easyplatform.commonvo.tag.vo.ExtendTagDicVO " alias="extendTagDicVO" />





위의 두 vo설정 코드에서 이름과 경로가 다르다는 것 외의 또하나의 차이점을 발견 하였는가?


저기서 둘중 하나의 코드때문에 vo를 찾지 못하는 에러가 나타나게 된다.


아직 모르겠다면 아래쪽의 코드를 잘 살펴 보도록 하자


그것은 경로가 들어가야 하는 부분에 포함되어 있는 공백 때문이다.

<typeAlias type="egovframework.easyplatform.commonvo.tag.vo.ExtendTagDicVO " alias="extendTagDicVO" />

<typeAlias type="egovframework.easyplatform.commonvo.tag.vo.ExtendTagDicVO" alias="extendTagDicVO" />


이렇게 보면 좀더 확인 하기 쉬울 것이다.


vo클래스의 경로를 넣어 주는 부분에 복사 붙여넣기를 하다보면 공백이 들어가는 경우가 종종 생긴다.


그럴때 분명히 경로는 맞는데 왜 클래스를 찾지 못하는지 모르겠다면 공백이 들어가있는지를 확인해 보도록 하자.






심각: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alarmService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private egovframework.경로.GenericDao egovframework.easyplatform.common.alarm.service.impl.AlarmServiceImpl.genericDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in file [C:\eGovFrameDev-3.5.1-64bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\easy-common\WEB-INF\classes\egovframework\spring\context-sqlMap.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [egovframework/sqlmap/example/sql-map-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework.경로.tag.vo.ExtendTagDicVO

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:301)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private egovframework.경로.generic.GenericDao egovframework.easyplatform.common.alarm.service.impl.AlarmServiceImpl.genericDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in file [C:\eGovFrameDev-3.5.1-64bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\easy-common\WEB-INF\classes\egovframework\spring\context-sqlMap.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [egovframework/sqlmap/example/sql-map-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework경로.tag.vo.ExtendTagDicVO

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:522)

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:298)

... 22 more

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in file [C:\eGovFrameDev-3.5.1-64bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\easy-common\WEB-INF\classes\egovframework\spring\context-sqlMap.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [egovframework/sqlmap/example/sql-map-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework경로.tag.vo.ExtendTagDicVO

at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1021)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:964)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:494)

... 24 more

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in file [C:\eGovFrameDev-3.5.1-64bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\easy-common\WEB-INF\classes\egovframework\spring\context-sqlMap.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [egovframework/sqlmap/example/sql-map-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework.경로.tag.vo.ExtendTagDicVO

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)

at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:450)

at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:424)

at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)

at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:178)

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)

... 35 more

Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [egovframework/sqlmap/example/sql-map-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework경로.tag.vo.ExtendTagDicVO

at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:430)

at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:336)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)

... 47 more

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework.경로.tag.vo.ExtendTagDicVO

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:106)

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89)

at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:424)

... 50 more

Caused by: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'extendTagDicVO'. Cause: java.lang.ClassNotFoundException: Cannot find class:  egovframework.경로.tag.vo.ExtendTagDicVO

at org.apache.ibatis.builder.xml.XMLConfigBuilder.typeAliasesElement(XMLConfigBuilder.java:127)

at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:96)

... 52 more

Caused by: java.lang.ClassNotFoundException: Cannot find class:  egovframework.경로.tag.vo.ExtendTagDicVO

at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188)

at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87)

at org.apache.ibatis.io.Resources.classForName(Resources.java:254)

at org.apache.ibatis.builder.xml.XMLConfigBuilder.typeAliasesElement(XMLConfigBuilder.java:120)

... 53 more

스프링 관련해서 여기저기 코드를 끌어다 쓰다보면 프로퍼티를 추가 해 주어야 하는 경우가 있다.


기본적으로 전자정부 프레임워크의 기본 샘플 프로젝트에서는 메세지 프로퍼티가 있지만


그건 메세지 소스에 추가 되어 있고 (사실 나도 잘 모름)


그냥 노멀하게 프로퍼티를 추가 하고 싶다 라고 하면 생각보다 굉장히 간단하니 아래 코드를 참고 하여 배워보자




1. 프로퍼티 생성


일단 main 폴더 아래에 resources 폴더 밑에 프로퍼티를 넣어놓을 폴더를 생성하고 그 안에


프로퍼티를 넣는다.


간략히 resources 폴더 밑에 property 라는 폴더를 만들어 file.properties 라는 프로퍼티를 넣어 놓았다.


(이름이 똑같은 필요는 없으니 알아서 하시길)



2. 프로퍼티 추가 등록


전자정부프레임워크의 spring 폴더 밑에 


context-common.xml 이라는 파일이 있다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 
    <context:component-scan base-package="egovframework">
       <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
 
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:/egovframework/message/message-common</value>
                <value>classpath:/egovframework/rte/fdl/idgnr/messages/idgnr</value>
                <value>classpath:/egovframework/rte/fdl/property/messages/properties</value>
            </list>
        </property>
        <property name="cacheSeconds">
            <value>60</value>
        </property>
    </bean>
    
    <bean id="leaveaTrace" class="egovframework.rte.fdl.cmmn.trace.LeaveaTrace">
        <property name="traceHandlerServices">
            <list>
                <ref bean="traceHandlerService" />
            </list>
        </property>
    </bean>
 
    <bean id="traceHandlerService" class="egovframework.rte.fdl.cmmn.trace.manager.DefaultTraceHandleManager">
        <property name="reqExpMatcher">
            <ref bean="antPathMater" />
        </property>
        <property name="patterns">
            <list>
                <value>*</value>
            </list>
        </property>
        <property name="handlers">
            <list>
                <ref bean="defaultTraceHandler" />
            </list>
        </property>
    </bean>
    
    <bean id="antPathMater" class="org.springframework.util.AntPathMatcher" />
    <bean id="defaultTraceHandler" class="egovframework.rte.fdl.cmmn.trace.handler.DefaultTraceHandler" />
</beans>
 

cs


기본적으로 이런 모양새 인데 


 

먼저 가장 위에 beans 설정하는 schemaLocation 부분에 


 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd


이 주소를 추가해주자


1
2
3
4
5
6
<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:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
cs



이렇게 되도록



그리고 


<util:properties id="fileProperties" location="classpath:/프로티 경로" />


를 beans 안에 추가 해 주도록 한다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?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:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
 
    <context:component-scan base-package="egovframework">
       <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
 
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:/egovframework/message/message-common</value>
                <value>classpath:/egovframework/rte/fdl/idgnr/messages/idgnr</value>
                <value>classpath:/egovframework/rte/fdl/property/messages/properties</value>
            </list>
        </property>
        <property name="cacheSeconds">
            <value>60</value>
        </property>
    </bean>
    
    <bean id="leaveaTrace" class="egovframework.rte.fdl.cmmn.trace.LeaveaTrace">
        <property name="traceHandlerServices">
            <list>
                <ref bean="traceHandlerService" />
            </list>
        </property>
    </bean>
 
    <bean id="traceHandlerService" class="egovframework.rte.fdl.cmmn.trace.manager.DefaultTraceHandleManager">
        <property name="reqExpMatcher">
            <ref bean="antPathMater" />
        </property>
        <property name="patterns">
            <list>
                <value>*</value>
            </list>
        </property>
        <property name="handlers">
            <list>
                <ref bean="defaultTraceHandler" />
            </list>
        </property>
    </bean>
    
    <bean id="antPathMater" class="org.springframework.util.AntPathMatcher" />
    <bean id="defaultTraceHandler" class="egovframework.rte.fdl.cmmn.trace.handler.DefaultTraceHandler" />
     
 
    <util:properties id="fileProperties" location="classpath:/property/file.properties" />
</beans>
 
cs



이렇게 추가를 하면 된다.



3. JAVA에서 사용 하기.



사용할 클래스에 


@Resource(name = "fileProperties")

private Properties fileProperties;


이런 코드를 추가 하여 준다. 어노테이션을 사용 하여 빈즈에서 끌어다 쓰는 것 같은데


저 위에 추가한 부분 id 를 이름으로 가져 오는 듯 하다.



그리고 메소드 내부에서 사용 할땐 아래 코드를 추가 하여 사용하고


String uploadPath = fileProperties.getProperty("가져올 데이터 이름");


간략히 코드를 구현하자면 아래와 같은 코드로 사용 하면 된다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
@Service("commonFileService")
public class CommonFileServiceImpl implements CommonFileService {
    // 이렇게 어노테이션을 이용하여 불러오도록 준비하고
    @Resource(name = "fileProperties")
    private Properties fileProperties;
 
    @Override
    public 반환 fileUpload(MultipartHttpServletRequest mRequest) {
        // 저장되는 파일 리스트
        List<String> fileNameArray = new ArrayList<String>();
        
        // 이렇게 사용 한다.
        String uploadPath = fileProperties.getProperty("file.image.winPath");
 
 
        return 반환;
    }
    
 
}
 
cs



웹개발을 하다보면 많은 페이지마다 반복되어야 하는 것들이 있다


예를들어 페이지를 이동할때마다 권한 검사를 한다던가 로그를 기록해야 한다던가 하는 것들


또한 URL을 요청해 컨트롤러가 구동되기 전 혹은 구동된 후에 실행시키고 싶은 것들도 있다


그런 인터셉터 기능을 설정하는 방법을 알아 보자



1. dispatcher-servlet.xml 설정


1
2
3
4
5
6
7
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="localeChangeInterceptor" />
            </list>
        </property>
    </bean>
cs


이렇게 생겨먹은 부분이 있는데 이 List 사이에

<ref bean="localeChangeInterceptor" /> 얘는 건들이지 말고 그 밑에

<ref bean="id값" />을 넣어 준다


그리고 아래와 같은 코드를 추가 시켜 준다


1
2
3
4
5
6
7
8
<bean id="위에 추가한 id값" class="인터셉터 기능을 수행할 패키지경로.클래스명">
          <!-- 인증 체크가 필요 없는 URL 리스트  -->
      <property name="urls">
       <list>
            제외시킬 url 목록
       </list>
      </property>
  </bean
cs



다음은 실행시킬 java 클래스를 만든다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
package 패키지 경로;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
/**
* @패키지명 : 블로그용
* @파일명 : PlatformInterceptor.java
* @작성일 : 2016. 5. 23.
* @작성자 : "In Chee su"
* @설명 : 인터셉트
*/
public class 클래스명 extends HandlerInterceptorAdapter {
     
//  인증 체크가 필요 없는 URL 리스트  
 
List<String> urls;
 
 public void setUrls(List urls) {
  this.urls = urls;
 }
 
 
/* (non-Javadoc)
 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
 */
@Override
 public boolean preHandle(HttpServletRequest request,
   HttpServletResponse response, Object handler) throws Exception {
   // 기능을 수행하고 Controller를 실행 하려면
 
   // return true;
 
  
 
   // 특정 체크에서 일치하지 않는다면
 
   // response.sendRedirect("특정 에러 페이지로 보낸다");
 
   // return false;
 
    
    // 인증 체크가 필요 없는 URL 체크
 
          for(int i=0; i < urls.size(); i++){
         
                if (request.getRequestURI().matches(urls.get(i))) {
                System.out.println("== 인증 체크가 필요 없는 URL ============================");
                System.out.println("== URL : "+ urls.get(i) +" ============================");
                System.out.println("== return true ============================");
                System.out.println("== 인터셉터 종료 ============================");
                return true;
               }
         
         
               // 첫페이지가 로그인 페이지일 경우
             
               // 첫페이지 jsession때문에 request.getRequestURI().indexOf("/login/login.do") != -1 사용
             
               if(request.getRequestURI().indexOf(urls.get(i)) != -1){
             
                 return true;
         
           }
 
  
  }
 
 
// 세션이 있는지 체크
 
// 세션에 로그인한 정보가 있는지 체크
 
 
return true;
 }
 
 
}
 
 
cs



이렇게 만들면 된다.


회사에서 처음 노트북을 지급받고 이클립스 자바 등등등을 설치 한 후 실행을 해보면

404에러가 뜨는 경우가 많다. 경로를 찾지 못해서 나타나는 에러인데 

에러가 나는 부분도 없는데 에러가 나는 경우가 있다. 이런 경우 서버를 체크해보자!


보통 이런 경우는

서버에 루트 지정이 잘못된 경우이다.


해당서버 컨피그 폴더안에 있는


server.xml 파일 Context 태그 안에 path설정을 해주어야 한다. 


아마 path에 /프로젝트이름 

으로 되어 있거나 다른 이름들이 들어가 있는 경우일텐데

보통 그냥 "/" 이걸로 바꿔주면 실행이 될 것이다. 도메인 뒤에 다시 프로젝트이름이 나타나는건 보기 안좋기 때문에

그냥 저렇게 하는 듯 하다.



포스팅이 도움이 되셨다면 마우스를 조금만 움직여서 

공감하기를 눌러주세요 블로거에게 큰 힘이 됩니다~! 


해당경로에 파일이 있지만 실행시 해당 경로를 찾지 못하는 경우


/src/main/resources/egovframework/spring/com/context-security.xml


파일에 


<security:http pattern="/디렉토리이름/**" security="none"/>


을 추가해 준다.


2.


egov-com-social.xml 파일에


<mvc:resources mapping="/디렉토리이름/**" location="/디렉토리이름/" />


추가 해준다.


포스팅이 도움이 되셨다면 마우스를 조금만 움직여서 

공감하기를 눌러주세요 블로거에게 큰 힘이 됩니다~! 

+ Recent posts