250x250
    
    
  
                              Notice
                              
                            
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - Core Java
- MySQL
- Exception
- Source
- AJAX
- 설정
- Eclipse
- JDBC
- 오픈소스
- Thymeleaf
- Open Source
- jpa
- STS
- 문서
- MSSQL
- spring
- Tomcat
- maven
- Docker
- Python
- ubuntu
- SpringBoot
- IntelliJ
- error
- JavaScript
- PostgreSQL
- Spring Boot
- myBatis
- oracle
- git
                            Archives
                            
                        
                          
                          - Today
- Total
헤르메스 LIFE
[Properties] Java 개발 시 사용하게 되는 Properties 사용법 본문
728x90
    
    
  개발을 하다보면 Properties 를 많이 사용하게 됩니다.
DB 에 저장하기에는 무겁고, 그냥 하드코딩하기는 나중이 걱정스럽죠. 그리고, 생각보다 꽤 많은 부분에서 Properties는 사용되는 모습을 보게 됩니다.
그래서 하나하나 정리해보기로 했습니다.
1. Property Service ( 전자정부 프레임워크 )
참고 : www.egovframe.go.kr/wiki/doku.php?id=egovframework:rte:fdl:property
   <bean name="propertyService" class="egovframework.rte.fdl.property.impl.EgovPropertyServiceImpl" 
         destroy-method="destroy">
      <property name="properties">
         <map>
            <entry key="AAAA" value="1234"/>
         </map>
      </property>			
   </bean>@Resource(name="propertyService")
protected EgovPropertyService propertyService ;
 
@Test
public void testPropertiesService() throws Exception {
   assertEquals("1234",propertyService.getString("AAAA"));
}2. Spring Boot ( @Value Anotation )
appication.yml ( application.propertis 를 사용해도 같은 내용입니다.)
spring:
  profiles:
    active: local                       # 디폴트 환경
# properties 파일 내용
spring.profiles.active=local@RestController
@RequestMapping( value = { "api" } )
@PropertySource("classpath:appication.yml") 
public class TestController { 
	private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class); 
       
    @Value("${spring.profiles.active}") 
    private String env; 
    
    public @ResponseBody
    Map selectList( @RequestParam Map<String, Object> param, HttpServletRequest request ) throws Exception { 
    	if(env.equals("local")) {
        	return "simpleRestService.selectTestList( param );
        } else {
            return "simpleRestService.selectList( param );
        }
    } 
}
728x90
    
    
  'Spring Framework' 카테고리의 다른 글
| [Spring] MessageSource 사용법 (0) | 2021.04.02 | 
|---|---|
| [Spring] Controller Parameters (0) | 2021.03.02 | 
| [Spring] Log4J 사용 시 쿼리 로그가 두 번 찍히는 경우 (0) | 2021.01.14 | 
| [Spring Boot] DataSource를 이용한 Multi Database Connection 샘플 (0) | 2021.01.11 | 
| [Spring Boot] springboot 에서 jsp-config include 사용 (0) | 2021.01.11 | 
