Пожалуйста, помогите мне с этой ошибкой, и я новичок в весну.Так что я не могу понять с этой ошибкой, когда я пытаюсь запустить Test Data Source без Spring MVC веб-структуры
cd F:\NetBeansProjects\SpringContactApp; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_131" cmd /c "\"\"C:\\Program Files\\NetBeans 8.0.1\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath in.ezeon.capp.test.TestDataSource\" -Dexec.executable=java -Dexec.classpathScope=test -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.0.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
------------------------------------------------------------------------
Building SpringContactApp 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ SpringContactApp ---
Feb 04, 2019 12:15:40 PM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@531d72ca: startup date [Mon Feb 04 12:15:40 IST 2019]; root of context hierarchy
Feb 04, 2019 12:15:40 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:619)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:870)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:931)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:941)
at in.ezeon.capp.test.TestDataSource.main(TestDataSource.java:23)
Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2294)
at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2039)
at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 5 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Ниже приведены коды класса SpringRootConfig.java и класса TestDataSource.java. Я использую netbeans 8 и springframework.
package in.ezeon.capp.config;
import static java.lang.Boolean.TRUE;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
*
* @author admin
*/
@Configuration
@ComponentScan(basePackages = {"in.ezeon.capp.dao"})
public class SpringRootConfig {
//TODO: Services,DAO,DataSource,Email sender or some other business layer beans
@Bean
public BasicDataSource getDataSource()
{
BasicDataSource ds=new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
//ds.setUrl("jdbc:mysql://localhost:3306/capp_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false");//localhost//127.0.0.1
ds.setUrl("jdbc:mysql://localhost:3306/capp_db");
ds.setUsername("root");
ds.setPassword("dbadmin@123");//dbadmin@123
ds.setMaxTotal(2);
ds.setInitialSize(1);
ds.setTestOnBorrow(true);
ds.setValidationQuery("SELECT 1");
ds.setDefaultAutoCommit(TRUE);
return ds;
}
}
А также найдите скриншот ниже для этой ошибки.
введите описание изображения здесь