1. In Spring 3, properties were easily injected to bean class using @value annotations, but in 2.5, it had to be defined setter method for every property which needs injection (@value is not supported in 2.5)
In 3.0
class class01 {
@Value#{contextProperties['ws.user']}
private username;
In 2.5
class class01 {
private username;
public setUsername(Strping username) {
this.username = username
}
2. In Spring 3, the context component scan worked well and it didn't need to define beans in applicationContext.xml, but in 2.5, every bean had to be defined in the configuration file.
In 3.0
<context:component-scan base-package="com.xxx.xxx" />
In 2.5
<bean id="bean01" class="com.xxx.xxx.xxxx01" />
<bean id="bean02" class="com.xxx.xxx.xxxx02" />
...
3. In Spring 3, I used xml style configuration file and PropertyPlaceholderConfigurer wasn't needed. But, In 2.5, I was returned to properties file.
In 3.0
<util:properties id="contextProperties" location="classpath:database.xml"/>
....
....
<bean id="bean01" class="com.xxx.xxx.xxxx">
<property name="user" value="#{contextProperties['ws.user']}" />
</bean>
In 2.5
<bean class="org.springframework.beans.....PropertyPlaceholderConfigurer" >
<property name="location" value="database.properties" />
</bean>
....
....
<bean id="bean01" class="com.xxx.xxx.xxxx">
<property name="user" value="${db.user}" />
</bean>
4. I was stuck with an error.
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'WebServiceLocator' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'ws.user' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
...
...
This was occurred because Spring couldn't read *.properties files. However, I was certainly defined them.
In applicationContext.xml
<bean class="org.springframework.beans....PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>ConfigPrd_ko.properties</value>
<value>database.properties</value>
</list>
</property>
</bean>
the location of PropertyPlaceholderConfigurer was its problem. It was located in the middle of configuration file. After I changed its location to the top, it was solved. The definition of PropertyPlaceholderConfigurer should be placed higher than locations of any other bean definitions.
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean class="org.springframework.beans......PropertyPlaceholderConfigurer" >
<property name="locations">
<list>
<value>ConfigPrd_ko.properties</value>
<value>database.properties</value>
</list>
</property>
</bean>
...
...
<bean id=".... />
<bean id=".... />
댓글 없음:
댓글 쓰기