Spring
둘러보기로 가기
검색하러 가기
Java 기반의 개발 Framework인 Spring을 정리 한다.
- 홈페이지 : http://www.springsource.org/
- 다운로드 : http://www.springsource.org/download
- 라이선스 :
- 플랫폼 : Java
MVC 모델
- Browser
- ajax
- yui : Yahoo User Interface
- jQuery
- JavaScript 라이브러리
- JavaScript와 Asynchronous JavaScript + XML (Ajax) 프로그래밍을 단순화
- Drag & Drop 같은 Dynamic한 페이지 구성
- View
-
- JSP를 대체하여 적의양의 코드와 빠른 렌더링 속도를 보장
- Templet 방식이기 때문에 다양한 출력양식을 지원함
- JSF : Java Server Face
- Tiles
- Control
- Spring
- Model
환경 설정
- Library
struts2-spring-plugin-2.2.1.jar org.springframework.*.jar
- /WEB-INF/web.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/classes/spring-common.xml, /WEB-INF/classes/spring-approve.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
- /WEB-INF/classes/struts.xml
<struts> <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> <constant name="struts.objectFactory.spring.autoWire" value="name" /> //--- 클래스명에 Spring에서 정의한 짧은 클래스명을 사용 한다. </struts>
- spring-approve.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd" default-autowire="byName"> <bean id="helloWorldAction" class="com.jopenbusiness.gae.approve.action.HelloWorldAction" scope="prototype" /> <bean id="loginAction" class="com.login.LoginAction" scope="prototype" /> </beans>
동시 세션 제어
- Spring Security 3.0을 사용하여 동시 세션 제어 가능
- Spring Security Feature : concurrent-session-control
- HTML
- 유효하지 않은 세션 ID에 대해서 URL 리다이렉트
<session-management invalid-session-url="/login.htm" />
- web.xml
<listener> <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher 또는 org.springframework.security.ui.session.HttpSessionEventPublisher </listener-class> </listener>
- Application Context
- 한 사용자가 동시에 두번 로그인하는 것을 방지 (두번째 사용자만 사용 가능)
<session-management> <concurrency-control max-sessions="1" /> </session-management>
- 두번째 로그인을 방지
<session-management> <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /> </session-management> 또는 <security:concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true" />
Filter
- /WEB-INF/web.xml
<filter> <filter-name>EappAuthFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>EappAuthFilter</filter-name> <url-pattern>*.do</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping>
- Spring IoC 선언 파일을 다음을 추가
<bean id="EappAuthFilter" class="com.naon.sso.EappAuthFilter" />
Annotation
- Annotation
- Java Code에 주석처럼 달아 특수한 의미를 부여해 주는 것으로 컴파일 타임 또는 런타임시 해석 됩니다.
- Spring에서 Annotation 사용 선언
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd" default-autowire="byName"> <context:component-scan base-package="anyframe.exercise.service" /> </beans>
- Annotation 사용 예
@Service("simpleService") public class SimpleServiceImpl implements SimpleService { @Resource private ApplicationContext context; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/web-config/spring-common.xml" }) public class LoggingTest {
- 참고 문헌