2016-06-14 2 views
0

jdbc 템플릿을 사용하여 데이터베이스를 호출 할 때 오류가 발생합니다. 내 코드에 문제가 좀 도와주세요 ..Spring Tomcat with MySQL 데이터베이스 오류

오류 : Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.

내 상황에 맞는 코드 :

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:jee="http://www.springframework.org/schema/jee"  xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee.xsd 
    http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.1.xsd"> 

<context:component-scan base-package="com.dmask" /> 
<context:annotation-config /> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /> 
    <property name="url" 
     value="jdbc:mysql://localhost:3306/dmask?useSSL=true" /> 
    <property name="username" value="root" /> 
    <property name="password" value="admin" /> 
</bean> 

<bean id="transactionManager" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
    <constructor-arg ref="dataSource" /> 
</bean> 

<bean id="bCryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" /> 

사람이 저를 도와주세요 알고 있다면 ..

+1

당신은 * 전체 * 스택 트레이스를 보여 주면 도움이 쉬울 수 있습니다. – Andreas

+1

고마워. 문제는 해결되었습니다. 참고 링크 : http : //stackoverflow.com/questions/26515700/mysql-jdbc-driver-5-1-33-time-zone-issue – nmkkannan

답변

0

도움이 될 수 있습니다.

<util:map id="dbProps"> 
    <entry key="db.driver" value="com.mysql.jdbc.Driver"/> 
    <entry key="db.jdbcurl" value="jdbc:mysql://localhost/world"/> 
    <entry key="db.username" value="myuser"/> 
    <entry key="db.password" value="mypass"/> 
</util:map> 


<bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${db.driver}"/> 
    <property name="url" value="${db.jdbcurl}"/> 
    <property name="username" value="${db.username}"/> 
    <property name="password" value="${db.password}"/> 
</bean> 

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="properties" ref="dbProps"/> 
</bean> 

대해 참조에서 : https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-spring-config.html