小组作业
在使用Spring框架创建 JDBC 连接时, 发生了几个问题, 我使用的IDE是 Intelij idea, 使用的数据库连接池是阿里巴巴提供的 Druid 数据库连接池, 也使用了 Maven 工具进行项目驱动的管理.
第一步:
类似于无框架的 JDBC 编程, 创建好 druid.properties 配置文件
第二步
创建了一个名为 applicationContext 的 xml 文件, 向里面添加了 bean 对象, 并配置了连接数据库需要的参数.
注意: 我的 applicationContext 文件是在resource 目录下的, 如果不在 resource 目录下需要对路径进行修改.
第三步:
test 目录下写了一个unit test 类, 测试一下连接是否正常.
第四步运行:
报错…
21:42:18.575 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3fc2959f: startup date [Sun Mar 29 21:42:18 BST 2020]; root of context hierarchy
21:42:18.870 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 2 bean definitions from class path resource [applicationContext.xml]
21:42:18.871 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@3fc2959f: org.springframework.beans.factory.support.DefaultListableBeanFactory@4c2bb6e0: defining beans [org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,dataSource]; root of factory hierarchy
21:42:18.913 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0'
21:42:19.015 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.driverClassName' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.url' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.username' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.password' in PropertySource 'localProperties' with value of type String
21:42:19.020 [main] DEBUG org.springframework.context.support