- 목표
Spring Framework 에서 꼭 필요한 Library와 설정 을 알아본다. - 학습
기본적으로 Spring framework를 사용하기 위해서 필요한, 기본 셋팅 정보
- JDK 1.6
- eclipse
- spring framwork
- commons-logging - Spring framework 에서 필수로 필요함
- jakarta-taglibs-standard Spring-MVC 에서 필수로 필요함
web.xml 설정
<!-- Filter Setting -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- Filter Setting -->
<!-- Spring Config Setting -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/*-context.xml
</param-value>
</context-param>
<!-- Spring Config Setting -->
<!-- listener Register -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- listener Register -->
<!-- Spring-MVC Config Setting -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Spring-MVC Config Setting -->
application-context.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: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-3.1.xsd">
<!-- component scan -->
<context:component-scan base-package="kr.pe.lahuman" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- component scan -->
</beans>
spring-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
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-3.1.xsd">
<!-- component scan -->
<context:component-scan base-package="kr.pe.lahuman"
use-default-filters="false">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- component scan -->
<!--
- This bean configures the 'prefix' and 'suffix' properties of
- InternalResourceViewResolver, which resolves logical view names
- returned by Controllers. For example, a logical view name of "vets"
- will be mapped to "/jsp/vets.jsp".
-->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:order="1" p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/jsp/" p:suffix=".jsp" />
</beans>
TestDao.java
@Repository
public class TestDao {
public String getData(String str){
return str;
}
}
TestServiceImpl.java
@Service
public class TestServiceImpl implements TestService {
@Autowired
private TestDao testDao;
@Override
public String getData(String str) {
return testDao.getData(str);
}
}
TestController.java
@Controller
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(value="/test.do")
public String testView(){
return testService.getData("test");
}
}
첨부파일 참조