반응형
아래에서 작성한 Spring xml 파일을 읽어들여 JSoup으로 Parsing하기 방법을 이용하여 spring에서 properties 파일을 읽어들여 static method에서 사용하였다.
우선 설정파일이다.
1 2 3 4 5 | /spring/g.properties value1=설정값1 (value1=\uC124\uC815\uAC121) value2=설정값2 (value2=\uC124\uC815\uAC122) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | context-common.xml <!--?xml version="1.0" encoding="UTF-8"?--> <!--?XML:NAMESPACE PREFIX = "[default] http://www.springframework.org/schema/beans" NS = "http://www.springframework.org/schema/beans" /--> < 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:util = "http://www.springframework.org/schema/util" xsi:schemalocation=" <!--?xml:namespace prefix = "context" /--> < context:component-scan base-package = "bugnote" > < context:exclude-filter type = "annotation" expression = "org.springframework.stereotype.Controller" > </ context:exclude-filter > < bean class = "org.springframework.core.LocalVariableTableParameterNameDiscoverer" > < bean id = "prop" class = "bugnote.common.Prop" > < property value = "classpath:/spring/g.properties" name = "propFile" > </ property > </ bean > </ bean ></ context:component-scan ></ beans > |
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 | Prop.java package bugnote.common; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.springframework.core.io.FileSystemResourceLoader; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; @Service ( "prop" ) public class Prop { private Properties _properties; public void setPropFile(String proFile) throws IOException { FileSystemResourceLoader fileSystemResourceLoader = new FileSystemResourceLoader(); Resource propResource = fileSystemResourceLoader.getResource(proFile); InputStream is = propResource.getInputStream(); _properties = new Properties(); _properties.load(is); } public String get(String key) { return _properties.getProperty(key); } } |
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 32 33 | BugnoteConst.java package bugnote.common; import javax.annotation.PostConstruct; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class BugnoteConst { @Autowired @Resource (name= "prop" ) public Prop prop; @PostConstruct public void init() { BugnoteConst.BUGNOTE_VALUE1 = prop.get( "value1" ); BugnoteConst.BUGNOTE_VALUE2 = prop.get( "value2" ); } public static String BUGNOTE_VALUE1; public static String BUGNOTE_VALUE2; public static final int SEARCH_RESULT_TEXT = 1 ; public static final int SEARCH_RESULT_XML = 2 ; public static final int SEARCH_RESULT_JSON = 3 ; public static final int SEARCH_TYPE_INTEGRATE = 4 ; ... ... } |
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 32 33 34 35 36 37 38 39 40 41 | MainController.java package kr.ictee.nsic.main; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import kr.ictee.nsic.common.NsicConst; import kr.ictee.nsic.common.NsicUtil; import kr.ictee.nsic.common.PageUtil; import kr.ictee.nsic.model.BbsVO; import kr.ictee.nsic.model.NSReguDataVO; import kr.ictee.nsic.repository.entity.ConvertMap; import kr.ictee.nsic.service.IWebService; import net.sf.json.JSONArray; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class MainController extends BaseController { //메인 리스트 @RequestMapping ( "/main.do" ) public ModelAndView main(HttpServletRequest req, HttpServletResponse res) throws Exception { ModelAndView mav = new ModelAndView(); logger.info( "value1 = " + BugnoteConst.BUGNOTE_VALUE1); // 이와 같이 일반적인 방법으로 사용하면 된다. mav.setViewName( "tiles.main" ); return mav; } } |
반응형
'컴퓨터관련' 카테고리의 다른 글
HtmlUnit 이용하여 Naver 로그인하기 (5) | 2016.03.23 |
---|---|
JSoup 이용하여 웹툰 다운로드하기 (0) | 2016.03.23 |
Spring xml 파일을 읽어들여 JSoup으로 Parsing하기 (0) | 2016.03.22 |
jQuery checkbox 선택된 항목 값 조회하기 (0) | 2016.02.13 |
Mysql Join 이용하여 update 하기 (0) | 2016.02.08 |