'Properties'에 해당되는 글 1건

  1. 2020.11.27 globals.properties를 util:properties로 JSP와 java에서 불러오기
Web&Spring2020. 11. 27. 09:46

 

 

 

util:properties를 이용하여 context 파일에 프로퍼티로 등록해 사용할 수 있다.

bean에 스키마를 추가하는것이 첫번째

다음은 나의 context-datasource.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:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
				        http://www.springframework.org/schema/jdbc  
				        http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
				        http://www.springframework.org/schema/util
				        http://www.springframework.org/schema/util/spring-util-4.0.xsd">
...

 

 

그다음엔..globals.properties를 빈의 초기값에 넣어서 설정을 해주고..

아래에 util:properties를 설정해준다.

 

	<bean id="egov.propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/egovframework/egovProps/globals.properties</value>
            </list>
        </property>
    </bean>

<!-- util:properties를 설정해준다. -->
<util:properties id="property" location="classpath:/egovframework/egovProps/globals.properties" />

 

 

 

나의 globals.properties는 이렇게 작성되어있고..

 

 

 

 

jsp파일에서 이렇게 끌어와서 쓸 수 있다.

<spring:eval expression="@property['Globals.usr.deerTest']/>

 

<html>
<head>
...

<body>
...
//jsp에서 이렇게 활용할 수 있다.
<input type="hidden" id="test" value="<spring:eval expression="@property['Globals.usr.deerTest']"/>
...
</body>
</html>

 

 

JAVA에서는 @Value 어노테이션을 쓰자!!!

물론 EgovPropertieService를 쓸수도 있고~!

 

@Value("#{propertie id['Globals.usr.deerTest']}")
String deerTest;

 

 

운영, 개발 나눠서 개발하기에 편하고, 소스코드를 재배포없이 관리할수 있어

당연히 properties를 적재적소에 잘 써줘야한다~!

Posted by 사슴영혼'-'