Application Configuration (Spring?)

I'm tired of all this boring code template to analyze application configurations such as database connections, working directories, API endpoints, and more. Spring IoC looks beautiful, but it will force the user of my application to modify the XML file only to edit the database URL and so on. It can also be very common in an XML file, where all the rest of my postings are.

What is the best method for allowing end users to configure services (which do not start inside the application server)? What are you guys using?

+5
source share
6 answers

Spring, ​​XML, - , "" , . .

. Spring Ibatis . :

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:database.properties"/>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${database.class}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
</bean>

database.properties( ):

database.username=scratch
database.password=scratch
database.class=oracle.jdbc.OracleDriver
database.url=jdbc:oracle:thin:@localhost:1521:XE
+10

PropertyPlaceholderConfigurer .

, applicationContext :

<bean id="dataSource" class="com.x.y.z.DataSource">
    <property name="url" value="${dataSource.url}" />
</bean>

dataSource.url .

, , , !

+5

, XML Spring , () URL- .. .

, XML , , , .

+2

Spring IOC ( XML, Java config, autowiring, ), , , .

PropertyPlaceholderConfigurer. , .

+2

You can modulate Spring configuration files. That way, you can have one XML file to connect to the database, which is then included (imported) in the central Spring configuration file. If the user should be able to modify the material, you can create XML files from the template and (re) load the application context.

0
source

Use org.springframework.beans.factory.config.PropertyPlaceholderConfigurerdescribed here:

http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-placeholderconfigurer

0
source

All Articles