Spring Legacy log4jdbc 설정 중 오류...ㅠ

2020. 8. 11. 13:41PC Program/Debug

반응형

 

 

책을 보며 Spring Legacy Project 차분히 따라하던 중에 Tomcat Server 실행 시 에러 메세지가 가득 올라오는 것을 보고 백방으로 찾아봤다...

 

INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue Aug 11 13:42:25 KST 2020]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.ExceptionInInitializerError
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.ExceptionInInitializerError

 

 

 

구글링을 통해 반드시 필요한 것 3가지 확인해 봤다..

 

1. log4jdbc.log4j2.properties 파일이 존재할 것

2. logback.xml이 존재할 것

3. root-context.xml 의 driverClassName과 url을 수정해줄 것.

 

우선 1번

 

src/main/resources/ 아래  log4jdbc.log4j2.properties 파일을 내용을 확인

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.slf4jSpyLogDelegator

 

2번

src/main/resources/ 아래 logback.xml 내용

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
	<include resource="org/springframework/boot/logging/logback/base.xml" />
	
	<!-- log4jdbc-log4j2 -->
	
	<logger name="jdbc.sqlonly" 			level="DEBUG" />
	<logger name="jdbc.sqltiming" 			level="INFO"  />
	<logger name="jdbc.audit" 			level="WARN"  />
	<logger name="jdbc.resultset" 			level="ERROR" />
	<logger name="jdbc.resultsettable" 		level="ERROR" />
	<logger name="jdbc.connection"			level="INFO"  />	

</configuration>

3번 

 

root-context.xml 의 dataSource 부분

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
	    
	    <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy" /> 
	    <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/translate?characterEncoding=UTF-8&amp;serverTimezone=UTC&amp;useSSL=false&amp;autoReconnect=true"></property>
	    <property name="username" value="${db.username}"></property> 
	    <property name="password" value="${db.password}"></property>
	    
 </bean>

 

다 존재 하는데 왜 안되는지 한참 찾다보니...

 

허무하게도 1번의 내용이 Slf4jSpyLogDelegator 에서 첫 글자를 소문자로 썼던것 때문에 발생하였다...

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator

java는 대소문자 구분이 철저하므로... 더 주의해야겠다..

 

반응형

'PC Program > Debug' 카테고리의 다른 글

HTTP Protocol Client 요청 GET, POST 방식  (0) 2020.09.14
Mybatis Where절 쓰기  (0) 2020.08.18