전통?적인 PropertyPlaceholderConfigurer 과 SpEL
전통적인? 방법과 SpEL을 사용해 properties파일 가져오는 방법
1. PropertyPlaceholderConfigurer 사용
2. SpEL 사용
아래 2개로 깔끔하게 처리
- <util:properties id="dataProps" location="classpath:properties/data.properties">
- #{dataProps['redis.host']}
1. PropertyPlaceholderConfigurer 사용
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" | |
xmlns:util="http://www.springframework.org/schema/util"> | |
<context:annotation-config /> | |
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> | |
<property name="locations"> | |
<list> | |
<value>classpath:properties/data.properties</value> | |
</list> | |
</property> | |
</bean> | |
<!-- Redis Source --> | |
<bean id="connectionFactory" | |
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> | |
<property name="hostName" value="${redis.host}" /> | |
<property name="port" value="${redis.port}" /> | |
<property name="password" value="${redis.password}" /> | |
</bean> | |
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> | |
<property name="connectionFactory" ref="connectionFactory" /> | |
</bean> | |
<!-- Redis Source --> | |
</beans> |
2. SpEL 사용
아래 2개로 깔끔하게 처리
- <util:properties id="dataProps" location="classpath:properties/data.properties">
- #{dataProps['redis.host']}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" | |
xmlns:util="http://www.springframework.org/schema/util"> | |
<context:annotation-config /> | |
<util:properties id="dataProps" | |
location="classpath:properties/data.properties" /> | |
<!-- Redis Source --> | |
<bean id="connectionFactory" | |
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> | |
<property name="hostName" value="#{dataProps['redis.host']}" /> | |
<property name="port" value="#{dataProps['redis.port']}" /> | |
<property name="password" value="#{dataProps['redis.password']}" /> | |
</bean> | |
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> | |
<property name="connectionFactory" ref="connectionFactory" /> | |
</bean> | |
<!-- Redis Source --> | |
</beans> |
댓글
댓글 쓰기