반응형
Notice
Recent Posts
Recent Comments
관리 메뉴

꿈꾸는 사람.

[Windows][MySQL 8.0.13][DataSource]Loading class `com.mysql.jdbc.Driver'. This is deprecated. 본문

IT/Database

[Windows][MySQL 8.0.13][DataSource]Loading class `com.mysql.jdbc.Driver'. This is deprecated.

현무랑 니니 2018. 12. 30. 19:19
반응형

스프링과 MyBatis를 함께 사용하기 위해 root-context.xml에 DataSource를 추가하여 JUnit로 테스트하면 

com.mysql.jdbc.Driver 클래스를 로딩할 때 오류가 발생한다.

이 오류는 com.mysql.jdbc.Driver가 오래되어 더이상 사용되지 않기 때문에 발생하며, 새로운 클래스인 com.mysql.cj.jdbc.Driver를 사용하면 해결된다고 한다. 

1. com.mysql.jdbc.Driver 관련 오류

Loading class `com.mysql.jdbc.Driver'. This is deprecated.

The new driver class is `com.mysql.cj.jdbc.Driver'. 

The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

2. 원인

nini01/src/main/webapp/WEB-INF/spring/root-context.xml 파일에서 driverClassName 정의가 이전 클래스를 사용하기 때문이다.

<bean id = "dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>

<property name="url" value="jdbc:mysql://127.0.0.1:3306/nini_schema"></property>

<property name="username" value="nini"></property>

<property name="password" value="test"></property>

</bean>

3. 수정

driverClassName을 com.mysql.cj.jdbc.Driver로 바꿔준다.

<bean id = "dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>

<property name="url" value="jdbc:mysql://127.0.0.1:3306/nini_schema"></property>

<property name="username" value="nini"></property>

<property name="password" value="test"></property>

</bean>

4. 해결

Run As >> JUnit Test 하여 테스트를 실행하면 Connection 객체, com.mysql.cj.jdbc.ConnectionImpl@4bc222e가 정상적으로 생성된 것을 확인할 수 있다.

INFO : org.springframework.test.context.TestContextManager - @TestExecutionListeners is not present for class [class com.nini.niniapp1.DataSourceTest]: using defaults.

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from file [C:\workspace-sts-3.7.3\nini01\src\main\webapp\WEB-INF\spring\appServlet\servlet-context.xml]

INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from file [C:\workspace-sts-3.7.3\nini01\src\main\webapp\WEB-INF\spring\root-context.xml]

INFO : org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@6aaa5eb0: startup date [Sun Dec 30 19:07:49 KST 2018]; root of context hierarchy

INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3bd94634: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,dataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy

INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.nini.niniapp1.HomeController.home(java.util.Locale,org.springframework.ui.Model)

INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'

INFO : org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: com.mysql.cj.jdbc.Driver

com.mysql.cj.jdbc.ConnectionImpl@4bc222e

INFO : org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@6aaa5eb0: startup date [Sun Dec 30 19:07:49 KST 2018]; root of context hierarchy

INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3bd94634: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,dataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy


반응형
Comments