프로젝트를 진행하다보면 파일안에 Properties 파일들을 저장해놓고 사용하는 일들이 자주 생긴다. 

가장 간단하게 사용하는 방법은 XML 혹은 JSON을 특정 경로에 넣고 파싱하는 방법이 있으나 설정파일을 사용하는 곳이 많아질 경우 복잡하다. 

스프링 프레임워크는 프레임워크 단에서 Properties 를 설정하는 방법을 가지고 있다.


Spring 설정 xml 안에 아래와 같은 설정을 추가한다. 

<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"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd">
	<context:component-scan base-package="com.tutorialspoint" />

	 <!-- context:property-placeholder location="classpath:database.properties"  /!-->
	<context:property-placeholder location="/WEB-INF/*.properties" />

</beans>


그럼 자동으로 WEB-INF 경로 아래에 있는 *.properties 밸류들이 로드된다.


스프링 내에서 사용하기 위해선 아래와 같이 사용한다.

@Component
class MyClass {
  @Value("${my.property.name}")
  private String[] myValues;
}


만약 위의 설정 방법이 안된다면 수동으로 빈을 생성해준다. 


<bean id="myProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>classpath*:my.properties</value>
    </list>
  </property>
</bean>

그리고 Resource 파일을 이용해서 불러들인다. 

@Component
class MyClass {
  @Resource(name="myProperties")
  private Properties myProperties;

  @PostConstruct
  public void init() {
    // do whatever you need with properties
  }
}



* 추가 

Project 진행시에 보통 개발, 테스트, 프로덕션 서버별로 배포를 다르게한다. 

각각의 환경마다 다른 설정값을 가지므로 배포시마다 사용하는 property 의 이름을 변경해주는 것은 여간 귀찮은 일이 아니다

다행이 스프링에서는 Profile 이라고 환경마다 다른 설정을 사용할수 있는 기능이 이미 내장되어있다. 

경로 부분을 지정해주고 ${spring.profiles.active} 코드를 넣어주면 Profile에 따라 설정값이 다르게 쓰인다. 

아래는 예제코드를 보면 profile 을 사용하시는 분들이라면 바로 이해가 갈것이다. 

<context:property-placeholder location="classpath:${spring.profiles.active}.properties" />



참고: 

1. http://jijs.tistory.com/entry/spring-%EC%84%A4%EC%A0%95-xml%EA%B3%BC-%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C%EC%97%90%EC%84%9C-properties-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

2. http://stackoverflow.com/questions/9259819/how-to-read-values-from-properties-file

3. http://nkjava.blogspot.kr/2013/07/springmvc-read-property-in-jsp.html

4. http://stackoverflow.com/questions/10669474/load-properties-file-in-spring-depending-on-profile

Scala IDE  를 받아서 압축을 푸는데 알수 없는 에러로 인해 계속 프로그램이 죽었는데 


구글링을 해보았더니 압축프로그램을 MAC 기본 내장에서 다른 프로그램으로 변경하니 실행이 잘되었다.


압축프로그램은 반디집을 이용하였다.



참고:

http://stackoverflow.com/questions/10876538/the-eclipse-executable-launcher-was-unable-to-locate-its-companion-launcher-jar

'Tools' 카테고리의 다른 글

Hyper-V 와 VirtualBox 쉽게 변경하기  (0) 2016.10.05
Eclipse Java doc comment 자동생성 단축키  (0) 2016.06.30

스프링으로 mybatis 를 사용할 경우 디폴트 설정만으로 충분한 경우가 많기때문에 따로 설정파일을 쓸경우를 제외하고는 디폴트 설정으로 쓰는편이다.

스프링의 같은경우 mybatis 설정들을 대부분 자동으로 해주기때문에 SqlSessionFactoryBean 에 mapper위치정도만 설정해놓고 자주 사용하는 편이자 


기본 스프링 설정파일을 아래와 같이 지정한후 보통 resources/mapper or resources/mybatis 아래에 둔다. 파일명은 mapper-config.xml 로 해두었다.

<?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:mybatis="http://mybatis.org/schema/mybatis-spring"
    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">
                        

 
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />        
        <property name="configLocation" value="classpath:/mapper/mybatis-config.xml" />        
		<property name="mapperLocations" value="classpath*:/mapper/**/*_SQL.xml" />
        
    </bean>
     
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSession"/>
    </bean>    
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="인터��이스로 맴퍼  자동맵퍼설정패키지" />
	</bean>
        
</beans>


classpath 위치 아래에 아래와 같이 만들어주어서 추가적인 설정을 해주면된다. 예제의 경우는 classpath 아래 mapper 폴더안에 mybatis-config.xml 을 사용했다. 


<?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:mybatis="http://mybatis.org/schema/mybatis-spring"
    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">
                        

 
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />        
        <property name="configLocation" value="classpath:/mapper/mybatis-config.xml" />        
		<property name="mapperLocations" value="classpath*:/mapper/**/*_SQL.xml" />
        
    </bean>
     
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSession"/>
    </bean>    
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="인터��이스로 맴퍼  자동맵퍼설정패키지" />
	</bean>

<typeHandlers>
  <typeHandler handler="org.mybatis.example.ExampleTypeHandler"/>
</typeHandlers>
        
</beans>


2년전 처음 맥을 사용하며 개발하면서 brew 를 통해서 프로그램들을 관리하면서 아주 많은 편리함을 느꼇다. 


현재 회사에서는 Windows 를 주로 이용해서 개발을 진행하는데 windows 에도 brew 같은 툴이 없나 살펴보니 chocolatey 같은 툴이 이미 나와 있었다.



https://chocolatey.org



기본적인 사용법은 brew 와 비슷한 형식으로 


커맨드 명령어로 프로그램을 설치하게 된다.


아래는 docker를 설치하기 위한 명령어다 



자세한 설치법을 알아보자.

MAC의 brew 를 연상시키면서 명령어 한줄로 설치가 가능하다. 자세한 순서는 아래와 같다. 


1. cmd 를 관리자 권한 실행



2. 아래 명령어 복사 붙여넣기

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"


이제 설치가 완료되었다. 


* chocolately 자체를 업데이트 할경우 아래명령어를 입력하면 자동으로 업데이트한다.


choco upgrade chocolatey 


필요한 패키지를 설치하기 위한 명령어를 알아보자. 


choco install 패키지이름


예)

choco install googlechrome

choco install jre8



패키지 삭제 명령어는 아래와 같다 .

choco uninstall  패키지 이름


예)

choco install googlechrome

choco install jre8


위 두명령어가 가장 자주 사용하는 명령어가 될겅디ㅏ.

더많은 명령어 관련은 아래 공식문서를 참조하자


https://chocolatey.org/docs

'ETC > Open Source' 카테고리의 다른 글

OpenCV 빌드시 파이썬 의존성 주의점  (0) 2016.10.27

Docker 를 사용하며 자주 사용하게 되는 기본 명령어 정리 

 

 

Docker 이미지 저장소 로그인

docker login <이미지 저장소 주소>

이미지 빌드

# 현재 폴더에 Dockerfile 이 있으릿
docker build --tag <이미지이름:이미지태그> . 

# Dockerfile 위치 임의 지정
docker build --tag <이미지이름:이미지태그> -f <Dockerfile 위치>

이미지 다운로드

docker pull 이미지 주소

현재 실행중인 컨테이너 리스트

docker container ls

 

컨테이너 로그 확인

docker log <컨테이너 ID>

# Tail 확인
docker log -f <컨테이너 ID>

+ Recent posts