Spring XML Configuration Properties file

Source: Internet
Author: User
Tags aop xmlns

Background: The database information is generally configured in the Db.properties file, but the properties file parsing is a troublesome thing

The STRUTS2 Integrated Spring Framework provides a way to parse the properties file, in the following steps:

1. Make the following configuration in Spring-all.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"
Xsi:schemalocation= "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd ">

<bean id= "Propertyconfigurer"
class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Locations" >
<list>
<value>classpath:properties/db.properties</value>
</list>
</property>
</bean>
<import resource= "Spring-db.xml"/>

</beans>

-------------------------------------------Small Cut---------------------

2, db.properties file to do the following configuration

#jdbc Properties, development environment
Jdbc.driverclassname=oracle.jdbc.driver.oracledriver
#jdbc. Url=jdbc:oracle:thin:@192.168.32.222:1521:smpdev
Jdbc.url=jdbc:oracle:thin: @localhost: 1521:ORCL
Jdbc.username=smp
#jdbc. Username=smpdev
#jdbc. USERNAME=SMP
Jdbc.password=linkage
#jdbc. PASSWORD=SMP

Jdbc.maxactive=20
jdbc.maxidle=2
Jdbc.minidle=1
jdbc.initialsize=2
Jdbc.accesstounderlyingconnectionallowed=true

-----------------------------------Small Cut---------------------------------

3, Spring-db.xml to do the following configuration

<?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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">

<!--database connection related definitions--

<!--development environment used--
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource"
destroy-method= "Close" >
<property name= "Driverclassname" >
<value>${jdbc.driverClassName}</value>
</property>
<property name= "url" >
<value>${jdbc.url}</value>
</property>
<property name= "username" >
<value>${jdbc.username}</value>
</property>
<property name= "Password" >
<value>${jdbc.password}</value>
</property>
<property name= "Maxactive" >
<value>${jdbc.maxActive}</value>
</property>
<property name= "Maxidle" >
<value>${jdbc.maxIdle}</value>
</property>
<property name= "Minidle" >
<value>${jdbc.minIdle}</value>
</property>
<property name= "InitialSize" >
<value>${jdbc.initialSize}</value>
</property>
<property name= "accesstounderlyingconnectionallowed" >
<value>${jdbc.accessToUnderlyingConnectionAllowed}</value>
</property>
</bean>

<bean id= "Lobhandler" class= "Org.springframework.jdbc.support.lob.DefaultLobHandler"/>
<bean id= "sqlmapclient" class= "Org.springframework.orm.ibatis.SqlMapClientFactoryBean" >
<property name= "Configlocations" >
<list>
<value>classpath:sqlmap-config.xml</value>
<!--
<value>classpath:sqlmap-config-plugin-service.xml</value>
<value>classpath:sqlmap-config-plugin.xml</value>
-
</list>
</property>
<property name= "DataSource" ref= "DataSource"/>
<property name= "Lobhandler" ref= "Lobhandler"/>
</bean>
</beans>

------------------------------Small Cut-------------------------

4, Lobhandler

Blob and CLOB fields in Oracle are processed with no additional coding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.