일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Eclipse
- Quartz
- JavaScript
- plugin
- 단축키
- profile
- IntelliJ
- port
- Windows 10
- ssh
- 줄바꿈 문자
- web.xml
- GIT
- maVen
- VirtualBox
- import
- xargs
- grep
- bash
- Source
- Windows
- 네트워크
- vscode
- resource
- context
- lsof
- Mac
- find
- netsh
- tomcat
- Today
- Total
develog
[Spring] Spring 2.5, Properties #2 본문
TestMainProperties.java
import my.PropClient; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestMainProperties { public static void main(String[] args) throws Exception { System.out.println("START"); System.out.println("------------------------------------------------"); ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-config.xml"); PropClient propClient = (PropClient) context.getBean("propClient");
System.out.println("propClient.getValue() : " + propClient.get("name11")); System.out.println("propClient.getValue() : " + propClient.get("name12")); System.out.println("------------------------------------------------"); System.out.println("END"); } } |
PropClient.java
package my; import java.util.Properties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class PropClient { @Autowired private Properties myProps; public String get(String key) { return myProps.getProperty(key); } } |
spring-config.xml
<beans default-autowire="no" default-lazy-init="false" default-dependency-check="none" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" 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 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <context:component-scan base-package="my" />
<util:properties id="myProps" location="classpath:sample.properties" />
</beans> |
sample.properties
name11=val11 name12=val12 |
'Dev > Spring' 카테고리의 다른 글
[Spring] Spring3 AOP 설정, xml or java (0) | 2015.06.04 |
---|---|
[Spring] static method injection (0) | 2014.11.11 |
[Spring] Spring 2.5, Properties (0) | 2014.11.10 |
[Spring] beans xml schema (0) | 2014.10.15 |
Spring 에서 HttpServletRequest 접근 (0) | 2013.12.11 |