<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@192.168.1.21:1521:XXX" />
<property name="username"><value>XXX</value></property>
<property name="password"><value>XXX</value></property>
<property name="maxActive"><value>80</value></property>
<property name="initialSize"><value>20</value></property>
<property name="maxWait"><value>60000</value></property>
<property name="maxIdle"><value>50</value></property>
<property name="minIdle"><value>3</value></property>
<property name="removeAbandoned"><value>true</value></property>
<property name="removeAbandonedTimeout"><value>180</value></property>
<property name="connectionProperties"><value>clientEncoding=GBK</value></property>
<property name="validationQuery"><value>select 1 from dual</value></property>
</bean>
以上是xml文件中一部分数据库配置
下面是java中的获取这些配置的代码:
import org.apache.commons.dbcp.BasicDataSource;//此处引入类的要与xml文件中的class文件一致
@Controller
public class OptimizationTerminalLonLatController {
@Autowired
BasicDataSource dataSource;
@RequestMapping(value = "/XXXX.XXX")
public void demo(){
String databaseUrl = dataSource.getUrl();//url连接
String username = dataSource.getUsername();//用户名
String password = dataSource.getPassword();//密码
............
}
}