简体   繁体   中英

Determining properties available for Spring Beans?

In the Spring Framework, how do you determine what "properties" and other related values are available to be set in the context.xml file(s)? For example, I need to set the isolation level of a TransactionManager. Would that be:

<property name="isolation" value="SERIALIZABLE" />
<property name="isolation_level" value="Isolation.SERIALIZABLE" />

or some other values?

Each bean represents a class, which you can easily find by class="" attribute. Now you simply open JavaDoc or source code of that class and look for all setters (methods following setFooBar() naming convention). You strip set prefix and un-capitalize the first character, making it fooBar . These are your properties.

In your particular case you are probably talking about PlatformTransactionManager and various implementations it has.

Putting the properties into . properties file is a good way of handling.

First define a properties file in your project structure. It is better to put .properties file with the same directory as spring applicationContext.xml.

Your properties file may seem like this :

isolation = "SERIALIZABLE"
isolation_level = Isolation.SERIALIZABLE

You can access this properties file by defining a spring bean like :

<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="location" value="classpath:YourProperties.properties"/>

</bean>

Finally you can access these properties inside Spring beans like :

  <bean id="BeanName" class="YourClass">

        <property name="PropertyName1" value="${isolation}"/>

        <property name="PropertyName" value="${isolation_level}"/>


    </bean>

There is another way to inject these values using annotations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM