【已解决】ERROR [main] - {dataSource-1} init errorjava.sql.SQLException: ${jdbc.driver}

报错如下

ERROR [main] - {dataSource-1} init error
java.sql.SQLException: ${jdbc.driver}
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:689)
	at com.alibaba.druid.pool.DruidDataSource.resolveDriver(DruidDataSource.java:1219)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:888)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1403)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1399)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:100)
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
	at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
	at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy10.queryStudents(Unknown Source)
	at test.main(test.java:19)

1. database.properties没有问题

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmnew?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
jdbc.username=root
jdbc.password=123456
jdbc.init=1
jdbc.minIdle=1
jdbc.maxActive=20

里面的username的root后面不要有空格!!! 这也可能导致报错,以前遇到过

还有最好加上时区

2. 考虑兼容问题:把数据库版本提高了,再次运行还是报错


   mysql
   mysql-connector-java
   8.0.27

3.  把applicationContext.xml配置文件重新写了一遍运行成功了

发现只有一个id不一样,离谱啊

【已解决】ERROR [main] - {dataSource-1} init errorjava.sql.SQLException: ${jdbc.driver}_第1张图片

 所以SqlSessionFactoryBean的id不能是sqlSessionFactory吗?

反正id改为sessionFactory以后运行确实不报错了

这里怀疑是会和spring自带的配置发生冲突

【已解决】ERROR [main] - {dataSource-1} init errorjava.sql.SQLException: ${jdbc.driver}_第2张图片

 修改如下:【已解决】ERROR [main] - {dataSource-1} init errorjava.sql.SQLException: ${jdbc.driver}_第3张图片

运行成功:

【已解决】ERROR [main] - {dataSource-1} init errorjava.sql.SQLException: ${jdbc.driver}_第4张图片

以下是完整代码



    
    
        
        
        
        
    
    
        
        
            classpath:com/lyx/mapper/*.xml
        
        
    
    
        
        
    
    
        
    


    

你可能感兴趣的:(报错,java,sql,数据库)