ÀüÀÚÁ¤ºÎ ÇÁ·¹ÀÓ¿öÅ© ½ºÇÁ¸µ ÇÁ·ÎÆÛƼ[properties] Ãß°¡ Çϱâ
½ºÇÁ¸µ °ü·ÃÇؼ ¿©±âÀú±â Äڵ带 ²ø¾î´Ù ¾²´Ùº¸¸é ÇÁ·ÎÆÛƼ¸¦ Ãß°¡ ÇØ ÁÖ¾î¾ß ÇÏ´Â °æ¿ì°¡ ÀÖ´Ù.
±âº»ÀûÀ¸·Î ÀüÀÚÁ¤ºÎ ÇÁ·¹ÀÓ¿öÅ©ÀÇ ±âº» »ùÇà ÇÁ·ÎÁ§Æ®¿¡¼´Â ¸Þ¼¼Áö ÇÁ·ÎÆÛƼ°¡ ÀÖÁö¸¸
±×°Ç ¸Þ¼¼Áö ¼Ò½º¿¡ Ãß°¡ µÇ¾î ÀÖ°í (»ç½Ç ³ªµµ Àß ¸ð¸§)
±×³É ³ë¸ÖÇÏ°Ô ÇÁ·ÎÆÛƼ¸¦ Ãß°¡ ÇÏ°í ½Í´Ù ¶ó°í ÇÏ¸é »ý°¢º¸´Ù ±²ÀåÈ÷ °£´ÜÇÏ´Ï ¾Æ·¡ Äڵ带 Âü°í ÇÏ¿© ¹è¿öº¸ÀÚ
1. ÇÁ·ÎÆÛƼ »ý¼º
ÀÏ´Ü main Æú´õ ¾Æ·¡¿¡ resources Æú´õ ¹Ø¿¡ ÇÁ·ÎÆÛƼ¸¦ ³Ö¾î³õÀ» Æú´õ¸¦ »ý¼ºÇÏ°í ±× ¾È¿¡
ÇÁ·ÎÆÛƼ¸¦ ³Ö´Â´Ù.
°£·«È÷ resources Æú´õ ¹Ø¿¡ property ¶ó´Â Æú´õ¸¦ ¸¸µé¾î file.properties ¶ó´Â ÇÁ·ÎÆÛƼ¸¦ ³Ö¾î ³õ¾Ò´Ù.
(À̸§ÀÌ ¶È°°Àº ÇÊ¿ä´Â ¾øÀ¸´Ï ¾Ë¾Æ¼ ÇϽñæ)
2. ÇÁ·ÎÆÛƼ Ãß°¡ µî·Ï
ÀüÀÚÁ¤ºÎÇÁ·¹ÀÓ¿öÅ©ÀÇ spring Æú´õ ¹Ø¿¡
context-common.xml À̶ó´Â ÆÄÀÏÀÌ ÀÖ´Ù.
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 42 43 44 45 46 47 48 49 50 51 52 | <?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:context="http://www.springframework.org/schema/context" 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/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="egovframework"> </context:component-scan> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>classpath:/egovframework/message/message-common</value> <value>classpath:/egovframework/rte/fdl/idgnr/messages/idgnr</value> <value>classpath:/egovframework/rte/fdl/property/messages/properties</value> </list> </property> <property name="cacheSeconds"> <value>60</value> </property> </bean> <bean id="leaveaTrace" class="egovframework.rte.fdl.cmmn.trace.LeaveaTrace"> <property name="traceHandlerServices"> <list> <ref bean="traceHandlerService" /> </list> </property> </bean> <bean id="traceHandlerService" class="egovframework.rte.fdl.cmmn.trace.manager.DefaultTraceHandleManager"> <property name="reqExpMatcher"> <ref bean="antPathMater" /> </property> <property name="patterns"> <list> <value>*</value> </list> </property> <property name="handlers"> <list> <ref bean="defaultTraceHandler" /> </list> </property> </bean> <bean id="defaultTraceHandler" class="egovframework.rte.fdl.cmmn.trace.handler.DefaultTraceHandler" /> </beans> |
±âº»ÀûÀ¸·Î ÀÌ·± ¸ð¾ç»õ Àε¥
¸ÕÀú °¡Àå À§¿¡ beans ¼³Á¤ÇÏ´Â schemaLocation ºÎºÐ¿¡
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
ÀÌ ÁÖ¼Ò¸¦ Ãß°¡ÇØÁÖÀÚ
1 2 3 4 5 6 | <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="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | cs |
ÀÌ·¸°Ô µÇµµ·Ï
±×¸®°í
<util:properties id="fileProperties" location="classpath:/ÇÁ·ÎƼ °æ·Î" />
¸¦ 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?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:context="http://www.springframework.org/schema/context" 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/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> <context:component-scan base-package="egovframework"> </context:component-scan> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>classpath:/egovframework/message/message-common</value> <value>classpath:/egovframework/rte/fdl/idgnr/messages/idgnr</value> <value>classpath:/egovframework/rte/fdl/property/messages/properties</value> </list> </property> <property name="cacheSeconds"> <value>60</value> </property> </bean> <bean id="leaveaTrace" class="egovframework.rte.fdl.cmmn.trace.LeaveaTrace"> <property name="traceHandlerServices"> <list> <ref bean="traceHandlerService" /> </list> </property> </bean> <bean id="traceHandlerService" class="egovframework.rte.fdl.cmmn.trace.manager.DefaultTraceHandleManager"> <property name="reqExpMatcher"> <ref bean="antPathMater" /> </property> <property name="patterns"> <list> <value>*</value> </list> </property> <property name="handlers"> <list> <ref bean="defaultTraceHandler" /> </list> </property> </bean> <bean id="defaultTraceHandler" class="egovframework.rte.fdl.cmmn.trace.handler.DefaultTraceHandler" /> <util:properties id="fileProperties" location="classpath:/property/file.properties" /> </beans> | cs |
ÀÌ·¸°Ô Ãß°¡¸¦ ÇÏ¸é µÈ´Ù.
3. JAVA¿¡¼ »ç¿ë Çϱâ.
»ç¿ëÇÒ Å¬·¡½º¿¡
@Resource(name = "fileProperties")
private Properties fileProperties;
ÀÌ·± Äڵ带 Ãß°¡ ÇÏ¿© ÁØ´Ù. ¾î³ëÅ×À̼ÇÀ» »ç¿ë ÇÏ¿© ºóÁî¿¡¼ ²ø¾î´Ù ¾²´Â °Í °°Àºµ¥
Àú À§¿¡ Ãß°¡ÇÑ ºÎºÐ id ¸¦ À̸§À¸·Î °¡Á® ¿À´Â µí ÇÏ´Ù.
±×¸®°í ¸Þ¼Òµå ³»ºÎ¿¡¼ »ç¿ë ÇÒ¶© ¾Æ·¡ Äڵ带 Ãß°¡ ÇÏ¿© »ç¿ëÇÏ°í
String uploadPath = fileProperties.getProperty("°¡Á®¿Ã µ¥ÀÌÅÍ À̸§");
°£·«È÷ Äڵ带 ±¸ÇöÇÏÀÚ¸é ¾Æ·¡¿Í °°Àº ÄÚµå·Î »ç¿ë ÇÏ¸é µÈ´Ù.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @Service("commonFileService") public class CommonFileServiceImpl implements CommonFileService { // ÀÌ·¸°Ô ¾î³ëÅ×À̼ÇÀ» ÀÌ¿ëÇÏ¿© ºÒ·¯¿Àµµ·Ï ÁغñÇÏ°í @Resource(name = "fileProperties") private Properties fileProperties; @Override public ¹Ýȯ fileUpload(MultipartHttpServletRequest mRequest) { // ÀúÀåµÇ´Â ÆÄÀÏ ¸®½ºÆ® List<String> fileNameArray = new ArrayList<String>(); // ÀÌ·¸°Ô »ç¿ë ÇÑ´Ù. String uploadPath = fileProperties.getProperty("file.image.winPath"); return ¹Ýȯ; } } | cs |
Ãâó: http://yamea-guide.tistory.com/category/Yame Programmer/ÀüÀÚÁ¤ºÎÇÁ·¹ÀÓ¿öÅ©?page=1 [±âŸġ´Â °³¹ßÀÚÀÇ ¾ß¸Å °¡À̵å]