1.0-SNAPSHOT
org.apache.maven.plugins
maven-compiler-plugin
77
jar
org.springframework
spring-context
5.2.6.RELEASE
org.springframework
spring-jdbc
5.2.7.RELEASE
org.springframework
spring-tx
5.2.7.RELEASE
mysql
mysql-connector-java
5.1.46
com.alibaba
druid
1.1.10
org.aspectj
aspectjweaver
1.8.9
junit
junit
4.12
compile
maven项目的代码结构:
在 spring 配置文件配置数据库连接池,配置 JdbcTemplate 对象,注入 DataSource。配置时用的是引用外部配置文件,所以还需要引入外部的属性文件,同时创建对象时是基于注解的所以还要开启组件扫描。
bean1.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:p=“http://www.springframework.org/schema/p”
xmlns:util=“http://www.springframework.org/schema/util”
xmlns:context=“http://www.springframework.org/schema/context”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package=“com.Keafmd”></context:component-scan>
<context:property-placeholder location=“classpath:jdbc.properties”/>
jdbc.properties:
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/user_db?characterEncoding=utf8&useUnicode=true&useSSL=false
jdbc.username=root
jdbc.password=root
============================================================================
相关的操作及注释都在代码中,请看代码。