2016-06-14 5 views
0

Я получаю сообщение об ошибке при вызове базы данных с использованием шаблона jdbc. Любая проблема в моем коде, пожалуйста, помогите мне ..Spring Tomcat с ошибкой базы данных 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

Это может быть проще, чтобы помочь, если вы покажете * полный * StackTrace. – 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> 

Refered от: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-spring-config.html