Chapter 9: Spring Integration"
From Documentation
Line 58: | Line 58: | ||
</beans> | </beans> | ||
+ | </source> | ||
+ | |||
+ | |||
+ | <source lang='java' high='1, 2'> | ||
+ | @Service("authService") | ||
+ | @Scope(value="singleton",proxyMode=ScopedProxyMode.TARGET_CLASS) | ||
+ | public class AuthenticationServiceImpl implements AuthenticationService,Serializable{ | ||
+ | ... | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | <source lang='java' high='2'> | ||
+ | @Component("sidebarPageConfigPagebase") | ||
+ | @Scope(value="request",proxyMode=ScopedProxyMode.TARGET_CLASS) | ||
+ | public class SidebarPageConfigPagebaseImpl implements SidebarPageConfig{ | ||
+ | ... | ||
+ | } | ||
</source> | </source> |
Revision as of 07:17, 31 January 2013
Overview
Spring Framework is a popular application development framework for enterprise Java. One key element is its infrastructural support: a light-weighted IoC (Inversion of Control) container that manages POJOs as Spring beans and their dependency relationship.
In this chapter, we won't create new example applications but will make previous examples integrated with Spring.
How to Integrate Spring Framework
The most common integration way is to let Spring manage an application's dependencies.
Configuration
Extracted from web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description><![CDATA[ZK Tutorial]]></description>
<display-name>ZK Tutorial</display-name>
<!-- ZK configuration-->
...
<!-- Spring configuration -->
<!-- Initialize spring context -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Enable webapp Scopes-->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>
WEB-INF/applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.zkoss.tutorial" />
</beans>
@Service("authService")
@Scope(value="singleton",proxyMode=ScopedProxyMode.TARGET_CLASS)
public class AuthenticationServiceImpl implements AuthenticationService,Serializable{
...
}
@Component("sidebarPageConfigPagebase")
@Scope(value="request",proxyMode=ScopedProxyMode.TARGET_CLASS)
public class SidebarPageConfigPagebaseImpl implements SidebarPageConfig{
...
}