Java Spring 连接达梦数据库完整配置示例 | 使用 DruidDataSource
以下是一个完整的 Spring 配置文件,用于连接达梦数据库,使用 com.alibaba.druid.pool.DruidDataSource:
<?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:context='http://www.springframework.org/schema/context'
xmlns:tx='http://www.springframework.org/schema/tx'
xsi:schemaLocation='http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd'>
<!-- 开启注解扫描 -->
<context:component-scan base-package='com.example' />
<!-- 数据源配置 -->
<bean id='dataSource' class='com.alibaba.druid.pool.DruidDataSource'>
<property name='url' value='jdbc:dm://localhost:5236/mydatabase' />
<property name='username' value='username' />
<property name='password' value='password' />
<!-- 其他数据源配置属性 -->
</bean>
<!-- 配置事务管理器 -->
<bean id='transactionManager' class='org.springframework.jdbc.datasource.DataSourceTransactionManager'>
<property name='dataSource' ref='dataSource' />
</bean>
<!-- 开启注解驱动 -->
<tx:annotation-driven />
<!-- 其他的Bean定义 -->
</beans>
在上面的配置文件中,你需要将 com.example 替换为你的应用程序的包名,jdbc:dm://localhost:5236/mydatabase 替换为你的达梦数据库的连接 URL,username 和 password 替换为你的数据库的用户名和密码。
这个配置文件定义了一个名为 dataSource 的 Druid 数据源,以及一个名为 transactionManager 的事务管理器。你可以根据需要添加其他的 Bean 定义,例如 DAO 或 Service。
原文地址: https://www.cveoy.top/t/topic/p10F 著作权归作者所有。请勿转载和采集!