프로젝트를 진행하다보면 파일안에 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>

프로젝트를 제작하며 사용하는 유용한 자바스크립트 라이브러리 모음 (2016-11-13 업데이트) 


Tabular: 테이블 표출

- 홈페이지: http://olifolkerd.github.io/tabulator/

- 사용법:https://www.sitepoint.com/dynamic-tables-json/


Kendo UI: 종합 UI  

- 홈페이지: http://www.telerik.com/kendo-ui


Flowchart.js: Flowchart 라이브러리

http://flowchart.js.org/


Fullcalendar

https://fullcalendar.io/



Webpack 을 사용하면서 개인적으로 자주 사용하게 되는 플러그인 목록 정리


1. CommonsChunkPlugin (https://github.com/webpack/docs/wiki/optimization) 

멀티페이지 어플리케이션의 경우 공통적으로 사용 되는 모듈들을 추적하여 따로 넣는 경우



참고:

1. 웹팩 플러그인 리스트: https://github.com/webpack/docs/wiki/list-of-plugins




1. 

stylesheets/

|

|-- modules/              # Common modules

|   |-- _all.scss         # Include to get all modules

|   |-- _utility.scss     # Module name

|   |-- _colors.scss      # Etc...

|   ...

|

|-- partials/             # Partials

|   |-- _base.sass        # imports for all mixins + global project variables

|   |-- _buttons.scss     # buttons

|   |-- _figures.scss     # figures

|   |-- _grids.scss       # grids

|   |-- _typography.scss  # typography

|   |-- _reset.scss       # reset

|   ...

|

|-- vendor/               # CSS or Sass from other projects

|   |-- _colorpicker.scss

|   |-- _jquery.ui.core.scss

|   ...

|

`-- main.scss            # primary Sass file



참고:

http://thesassway.com/beginner/how-to-structure-a-sass-project


2. 

OpenCV 를 리눅승[서 소스로부터 빌드하여 설치할때 주의할점



리눅스에서 OpenCV를 빌드하다가 아래와 같은 오류가 났었다. 구글링해서도 답이 잘나오지 않아서 cmake 를 위주로 검색을 하다보니 



/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC

/usr/local/lib/libpython2.7.a: could not read symbols: Bad value

collect2: ld returned 1 exit status


다른 파이썬을 의존하는 라이브러리들에서도 경로 문제로 같은 오류가 난다는 것을 힌트로 얻어 해결했다. 


일단 현재 환경에서는 기존 리눅스에서 내장으로 설치된 파이썬을 제외하고 두가지 버전이 설치되어 있다. 

opencv를 빌드하기 위해서 파이썬안의 libpython2.7.a 파일을 참조하게 되는데 두가지 파이썬이 설치되면서 이경우가 꼬인듯이 보였다.


$ locate libpython

$ sudo ln -s "사용하려는 파이썬의 libpython2.7.a 경로" "/usr/local/lib/libpython2.7.a"


EX) 필자는 아나콘다 환경에서 파이썬 환경을 관리하기 때문에 아래와 같이 설정했다.

sudo ln -s "아나콘다설치폴더/lib/python2.7/config/libpython2.7.a" "/usr/local/lib/libpython2.7.a"


참고:

1. http://stackoverflow.com/questions/29397965/unable-to-make-opencv-2-4-9-ubuntu-14-10

2. http://stackoverflow.com/questions/22990769/libpython-error-while-building-youcompleteme

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

윈도우즈판 brwe 프로그램 관리툴 Chocolatey  (0) 2016.11.12

Flask 를 윈도우에서 개발하여 리눅스 서버에 배포할 일이 생겼느데


리눅스에서는 잘만 설치되는 Flask 가 윈도우 가상환경에서는 오류를 뱉어내면서 설치되지 않았다.


해결방법이 두가지가 있는데 


setupuptools 의 최신버전에 의한 오류


구글에 알아보니 setupuptools 버전을 낮추는 방법과 Wheel 버전을 다운받아 설치하는 방법이 있었다. 


1. setuptools 를 이용한 방법은 아래와 같다. 

pip install setuptools==21.2.1

pip install flask


2. 설치파일 직접 다운로드 후 setup.py 실행

홈페이지에서 setup 관련 파일을 직접 다운받은후에 python 으로 바로 실행하도록 하자. 




참고:

http://stackoverflow.com/questions/38243633/falied-to-install-flask-under-virutalenv-on-windows-error-2-the-system-cann

+ Recent posts