OSGi.基于Spring,Hibernate的Web应用快速开发指南

时间:2021-05-25 15:15:40

1 准备开发工具

a) SpringSource Tool Suite 2.9.2.REALEASE:解压即可
http://download.springsource.com/release/STS/2.9.2/dist/e3.7/springsource-tool-suite-2.9.2.RELEASE-e3.7.2-win32-x86_64.zip

b) Virgo Tomcat Server 3.5.0.RELEASE:解压即可
http://eclipse.stu.edu.tw//virgo/release/VTS/3.5.0.RELEASE/virgo-tomcat-server-3.5.0.RELEASE.zip

c) Virgo插件:通过Update site安装
http://download.eclipse.org/virgo/milestone/tooling

2 运行SpringSource Tool Suite

a)  进入SpringSource安装目录/sts-2.9.2.RELEASE,点击STS.exe

3 创建Virgo Runtime

a) Window->Preferences->Server->Runtime Environment->add

b) 输入vi过滤,选中EclicpseRT下的Virgo Runtime,勾选Create a new local server,点击Next

c) 点击browse,选中Virgo Tomcat Server安装目录确定

4 管理Bundle依赖

a) 打开Server视图
Window->Show View->Server

b) 打开Server编辑器
在Server view中双击已创建好的Virgo Server

c) 进入Repository标签页
在Server编辑器下方点击Repository


d) 下载hibernate相关bundle
Repository标签页左上侧输入框输入antlr->点击search,勾选输入框下方搜索结果中的bundles:com.springsource.antlr,点击Repository标签页中间下方的download按钮,依次下载如下bundle
com.springsource.antlr-2.7.6.jar
com.springsource.com.mysql.jdbc-5.1.6.jar
com.springsource.javassist-3.3.0.ga.jar
com.springsource.net.sf.cglib-2.1.3.jar
com.springsource.org.apache.commons.collections-3.2.1.jar
com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar
com.springsource.org.apache.commons.pool-1.4.0.jar
com.springsource.org.dom4j-1.6.1.jar
com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar
com.springsource.org.hibernate.annotations-3.4.0.GA.jar
com.springsource.org.hibernate-3.3.1.GA.jar
com.springsource.org.jgroups-2.5.1.jar

e) 查看下载完毕的bundle
下载的bundle存放在Virgo服务器安装目录/Repository/usr目录下,如果不可见,尝试点击右侧Refresh按钮或右下方Update the bundle and library index链接,Virgo服务器安装目录/Repository/ext目录下存放的是服务器自带的bundle

5 开发Bundle

5.1 com.dw.test.datasource

a) 创建bundle项目
File->new->project,输入bun过滤,选中Virgo下的bundle项目->next,输入com.dw.test.datasource->next,勾选Enable Bundle Classpath Container,Target runtime下拉框选择Virgo Runtime->finish

b) 导入依赖包
双击src/META-INF/MANIFEST.MF->点击下方dependencies标签页->在Import Package区域点击Add按钮->输入com.mysql.jdbc,点击OK。按此步骤依次导入以下依赖包
com.mysql.jdbc,javax.sql,org.apache.commons.dbcp

c) 定义Spring bean
src/META-INF/spring/appContext.xml

 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xmlns = " http://www.springframework.org/schema/beans "
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xsi:schemaLocation = " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xmlns:p = " http://www.springframework.org/schema/p " >
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < bean id = " dataSource "   class = " org.apache.commons.dbcp.BasicDataSource "
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南         p:driverClassName = " com.mysql.jdbc.Driver "
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南         p:url = " jdbc:mysql://localhost:3306/test?autoReconnect=true "
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南         p:username = " root "  p:password = ""  init - method = " createDataSource "
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南         destroy - method = " close "   />
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >


d) 定义Spring OSGi bean
src/META-INF/spring/osgiContext.xml

 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xmlns = " http://www.springframework.org/schema/beans "  xmlns:osgi = " http://www.springframework.org/schema/osgi "
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xsi:schemaLocation = " http://www.springframework.org/schema/beans
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/beans/spring-beans.xsd
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/osgi
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/osgi /spring-osgi.xsd">
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < osgi:service ref = " dataSource "   interface = " javax.sql.DataSource "   />
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >


5.2 com.dw.test.domain

a) 创建
bundle项目,名为com.dw.test.domain,参考5.1 a

b)
导入依赖包javax.persistence,javassist.util.proxy,org.hibernate.proxy,参考5.1 b

c) 创建并导出共享包
创建包com.dw.test.domain,打开src/META-INF/MANIFEST.MF编辑器->点击runtime标签页->在Exported Packages区域点击Add按钮->输入com.dw.test.domain,点击OK

d) 创建entity
src/com.dw.test.domain.User.java

 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.domain;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.io.Serializable;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.Basic;
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.Entity;
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.GeneratedValue;
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.GenerationType;
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.Id;
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.persistence.Table;
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南 @Entity
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南 @Table(name  =   " user " )
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   class  User  implements  Serializable  {
15OSGi.基于Spring,Hibernate的Web应用快速开发指南
16OSGi.基于Spring,Hibernate的Web应用快速开发指南    private static final long serialVersionUID = 1L;
17OSGi.基于Spring,Hibernate的Web应用快速开发指南
18OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Id
19OSGi.基于Spring,Hibernate的Web应用快速开发指南    @GeneratedValue(strategy = GenerationType.AUTO)
20OSGi.基于Spring,Hibernate的Web应用快速开发指南    private Long id;
21OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Basic
22OSGi.基于Spring,Hibernate的Web应用快速开发指南    private String username;
23OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Basic
24OSGi.基于Spring,Hibernate的Web应用快速开发指南    private String password;
25OSGi.基于Spring,Hibernate的Web应用快速开发指南
26OSGi.基于Spring,Hibernate的Web应用快速开发指南    public Long getId() {
27OSGi.基于Spring,Hibernate的Web应用快速开发指南        return id;
28OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

29OSGi.基于Spring,Hibernate的Web应用快速开发指南
30OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void setId(Long id) {
31OSGi.基于Spring,Hibernate的Web应用快速开发指南        this.id = id;
32OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

33OSGi.基于Spring,Hibernate的Web应用快速开发指南
34OSGi.基于Spring,Hibernate的Web应用快速开发指南    public String getUsername() {
35OSGi.基于Spring,Hibernate的Web应用快速开发指南        return username;
36OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

37OSGi.基于Spring,Hibernate的Web应用快速开发指南
38OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void setUsername(String username) {
39OSGi.基于Spring,Hibernate的Web应用快速开发指南        this.username = username;
40OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

41OSGi.基于Spring,Hibernate的Web应用快速开发指南
42OSGi.基于Spring,Hibernate的Web应用快速开发指南    public String getPassword() {
43OSGi.基于Spring,Hibernate的Web应用快速开发指南        return password;
44OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

45OSGi.基于Spring,Hibernate的Web应用快速开发指南
46OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void setPassword(String password) {
47OSGi.基于Spring,Hibernate的Web应用快速开发指南        this.password = password;
48OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

49OSGi.基于Spring,Hibernate的Web应用快速开发指南
50OSGi.基于Spring,Hibernate的Web应用快速开发指南}

51 OSGi.基于Spring,Hibernate的Web应用快速开发指南

5.3 com.dw.test.dao

a) 创建bundle项目,名为com.dw.test.dao,参考5.1 a

b) 引入项目com.dw.test.domain
右键项目->点击Properties->选中Project References->勾选com.dw.test.domain->点击OK

c) 导入依赖包com.dw.test.domain,参考5.1 b

d) 创建并导出共享包com.dw.test.dao,参考5.2 c

e) 创建IBaseDao基类接口
src/com.dw.test.dao.IBaseDao
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.dao;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.io.Serializable;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   interface  IBaseDao < T >   {
 6OSGi.基于Spring,Hibernate的Web应用快速开发指南
 7OSGi.基于Spring,Hibernate的Web应用快速开发指南    void save(T entity);
 8OSGi.基于Spring,Hibernate的Web应用快速开发指南    
 9OSGi.基于Spring,Hibernate的Web应用快速开发指南    void update(T entity);
10OSGi.基于Spring,Hibernate的Web应用快速开发指南    
11OSGi.基于Spring,Hibernate的Web应用快速开发指南    void delete(T entity);
12OSGi.基于Spring,Hibernate的Web应用快速开发指南
13OSGi.基于Spring,Hibernate的Web应用快速开发指南    T findById(Serializable id);
14OSGi.基于Spring,Hibernate的Web应用快速开发指南
15OSGi.基于Spring,Hibernate的Web应用快速开发指南}

f) 创建IUserDao业务接口
src/com.dw.test.dao.IUserDao
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package com.dw.test.dao;
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import com.dw.test.domain.User;
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public interface IUserDao extends IBaseDao < User > {
7OSGi.基于Spring,Hibernate的Web应用快速开发指南
8OSGi.基于Spring,Hibernate的Web应用快速开发指南}

5.4 com.dw.test.dao.impl

a) 创建bundle项目,名为com.dw.test.dao.impl,参考5.1 a

b) 引入项目com.dw.test.domain,com.dw.test.dao,参考5.3 b

c) 导入依赖包com.dw.test.domain,com.dw.test.dao,javax.sql,参考5.1 b

d) 导入Hibernate bundle
双击src/META-INF/MANIFEST.MF -> 点击下方dependencies标签页 -> 在Import Bundle区域点击Ad d按钮->输入 com.springsource.org.hibernate,点击OK。

e) 导入Spring库
双击src/META-INF/MANIFEST.MF -> 点击下方dependencies标签页 -> 在Import Library区域点击Ad d按钮->输入 org.springframework.spring,点击OK。

f) 实现IBaseDao接口
src/com.dw.test.dao.impl.BaseDaoImpl.java
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.dao.impl;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.io.Serializable;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.lang.reflect.ParameterizedType;
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.lang.reflect.Type;
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.dao.IBaseDao;
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   abstract   class  BaseDaoImpl < T >   extends
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南        HibernateDaoSupport  implements  IBaseDao < T >   {
13OSGi.基于Spring,Hibernate的Web应用快速开发指南
14OSGi.基于Spring,Hibernate的Web应用快速开发指南    protected Class<T> entityclass;
15OSGi.基于Spring,Hibernate的Web应用快速开发指南
16OSGi.基于Spring,Hibernate的Web应用快速开发指南    public BaseDaoImpl() {
17OSGi.基于Spring,Hibernate的Web应用快速开发指南        entityclass = getEntityClass();
18OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

19OSGi.基于Spring,Hibernate的Web应用快速开发指南
20OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
21OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void save(T entity) {
22OSGi.基于Spring,Hibernate的Web应用快速开发指南        getHibernateTemplate().save(entity);
23OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

24OSGi.基于Spring,Hibernate的Web应用快速开发指南
25OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
26OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void update(T entity) {
27OSGi.基于Spring,Hibernate的Web应用快速开发指南        getHibernateTemplate().update(entity);
28OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

29OSGi.基于Spring,Hibernate的Web应用快速开发指南
30OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
31OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void delete(T entity) {
32OSGi.基于Spring,Hibernate的Web应用快速开发指南        getHibernateTemplate().delete(entity);
33OSGi.基于Spring,Hibernate的Web应用快速开发指南    }
;
34OSGi.基于Spring,Hibernate的Web应用快速开发指南    
35OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
36OSGi.基于Spring,Hibernate的Web应用快速开发指南    public T findById(Serializable id) {
37OSGi.基于Spring,Hibernate的Web应用快速开发指南        T entity = getHibernateTemplate().get(entityclass, id);
38OSGi.基于Spring,Hibernate的Web应用快速开发指南        return entity;
39OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

40OSGi.基于Spring,Hibernate的Web应用快速开发指南
41OSGi.基于Spring,Hibernate的Web应用快速开发指南    @SuppressWarnings("unchecked")
42OSGi.基于Spring,Hibernate的Web应用快速开发指南    protected Class<T> getEntityClass() {
43OSGi.基于Spring,Hibernate的Web应用快速开发指南        Type type = getClass().getGenericSuperclass();
44OSGi.基于Spring,Hibernate的Web应用快速开发指南        Class<T> result = null;
45OSGi.基于Spring,Hibernate的Web应用快速开发指南        if (type instanceof ParameterizedType) {
46OSGi.基于Spring,Hibernate的Web应用快速开发指南            ParameterizedType parameterizedType = (ParameterizedType) type;
47OSGi.基于Spring,Hibernate的Web应用快速开发指南            result = (Class<T>) parameterizedType.getActualTypeArguments()[0];
48OSGi.基于Spring,Hibernate的Web应用快速开发指南        }

49OSGi.基于Spring,Hibernate的Web应用快速开发指南        return result;
50OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

51OSGi.基于Spring,Hibernate的Web应用快速开发指南
52OSGi.基于Spring,Hibernate的Web应用快速开发指南}

g) 实现IUserDao接口
src/com.dw.test.dao.impl.UserDaoImpl.java
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package com.dw.test.dao.impl;
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import org.springframework.stereotype.Repository;
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import com.dw.test.dao.IUserDao;
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import com.dw.test.domain.User;
7 OSGi.基于Spring,Hibernate的Web应用快速开发指南
8 OSGi.基于Spring,Hibernate的Web应用快速开发指南
9 OSGi.基于Spring,Hibernate的Web应用快速开发指南@Repository( " userDao " )
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public class UserDaoImpl extends BaseDaoImpl < User > implements IUserDao {
11OSGi.基于Spring,Hibernate的Web应用快速开发指南
12OSGi.基于Spring,Hibernate的Web应用快速开发指南}

h) 定义Spring Bean
src/META-INF/spring/appContext.xml
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 " encoding = " UTF-8 " ?>
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns = " http://www.springframework.org/schema/beans "
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xmlns:context = " http://www.springframework.org/schema/context "
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xsi:schemaLocation = " http://www.springframework.org/schema/beans
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/beans/spring-beans.xsd
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context
7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context/spring-context.xsd" default-autowire="byName">
8 OSGi.基于Spring,Hibernate的Web应用快速开发指南
9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < context:annotation - config />
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < context:component - scan base - package = " com.dw.test " />
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < bean id = " sessionFactory " class = " org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean " >
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " dataSource " ref = " dataSource " />
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " schemaUpdate " value = " false " />
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " hibernateProperties " >
17 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < props >
18 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < prop key = " hibernate.dialect " >
19 OSGi.基于Spring,Hibernate的Web应用快速开发指南 org.hibernate.dialect.MySQLDialect
20 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ prop >
21 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < prop key = " hibernate.show_sql " > true </ prop >
22 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < prop key = " cache.provider_class " > org.hibernate.cache.NoCacheProvider </ prop >
23 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ props >
24 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ property >
25 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " annotatedClasses " >
26 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < list >
27 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < value > com.dw.test.domain.User </ value >
28 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ list >
29 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ property >
30 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ bean >
31 OSGi.基于Spring,Hibernate的Web应用快速开发指南
32 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < bean id = " transactionManager " class = " org.springframework.orm.hibernate3.HibernateTransactionManager " >
33 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " sessionFactory " ref = " sessionFactory " />
34 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ bean >
35 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >

i) 定义OSGi bean

src/META-INF/spring/osgiContext.xml
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns = " http://www.springframework.org/schema/beans "
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南    xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南    xsi:schemaLocation = " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd "
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南     xmlns:osgi = " http://www.springframework.org/schema/osgi " >
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < osgi:reference id = " dataSource "   interface = " javax.sql.DataSource "   />
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南    
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < osgi:service ref = " sessionFactory "   interface = " org.hibernate.SessionFactory "   />
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < osgi:service ref = " transactionManager "   interface = " org.springframework.transaction.PlatformTransactionManager "  context - class - loader = " service-provider "   />
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < osgi:service ref = " userDao "   interface = " com.dw.test.dao.IUserDao "   />
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >

5.5 com.dw.test.service

a) 创建bundle项目,名为com.dw.test.service,参考5.1 a

b) 引入项目com.dw.test.domain,com.dw.test.dao,参考5.3 b

c) 导入依赖包com.dw.test.domain,com.dw.test.dao,参考5.1 b

d) 创建并导出共享包com.dw.test.service,参考5.2 c

e) 创建IBaseService类接口
src/com.dw.test.service.IBaseService
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.service;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.io.Serializable;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   interface  IBaseService < T >   {
 7OSGi.基于Spring,Hibernate的Web应用快速开发指南
 8OSGi.基于Spring,Hibernate的Web应用快速开发指南    void create(T entity);
 9OSGi.基于Spring,Hibernate的Web应用快速开发指南
10OSGi.基于Spring,Hibernate的Web应用快速开发指南    void modify(T entity);
11OSGi.基于Spring,Hibernate的Web应用快速开发指南
12OSGi.基于Spring,Hibernate的Web应用快速开发指南    void remove(T entity);
13OSGi.基于Spring,Hibernate的Web应用快速开发指南
14OSGi.基于Spring,Hibernate的Web应用快速开发指南    T getById(Serializable id);
15OSGi.基于Spring,Hibernate的Web应用快速开发指南    
16OSGi.基于Spring,Hibernate的Web应用快速开发指南}

f) 创建IUserService业务接口
src/com.dw.test.service.IUserService
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.service;
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.domain.User;
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   interface  IUserService  extends  IBaseService < User >   {
6OSGi.基于Spring,Hibernate的Web应用快速开发指南
7OSGi.基于Spring,Hibernate的Web应用快速开发指南}

5.6 com.dw.test.service.impl
a) 创建bundle项目,名为com.dw.test.service.impl,参考5.1 a

b) 引入项目com.dw.test.domain,com.dw.test.dao,com.dw.test.service参考5.3 b

c) 导入依赖包,com.dw.test.dao,com.dw.test.domain,com.dw.test.service,org.aopalliance.aop,参考5.1 b

d) 导入Hibernate bundle,参考5.4 d

e) 导入Spring库,参考5.4 e

f) 实现IBaseService接口
src/com.dw.test.service.impl.BaseServiceImpl.java
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.service.impl;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  java.io.Serializable;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.dao.IBaseDao;
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.service.IBaseService;
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   abstract   class  BaseServiceImpl < T >   implements  IBaseService < T > {
 9OSGi.基于Spring,Hibernate的Web应用快速开发指南    
10OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
11OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void create(T entity) {
12OSGi.基于Spring,Hibernate的Web应用快速开发指南        System.out.println(getBaseDao() == null);
13OSGi.基于Spring,Hibernate的Web应用快速开发指南        getBaseDao().insert(entity);
14OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

15OSGi.基于Spring,Hibernate的Web应用快速开发指南
16OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
17OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void modify(T entity) {
18OSGi.基于Spring,Hibernate的Web应用快速开发指南        getBaseDao().update(entity);
19OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

20OSGi.基于Spring,Hibernate的Web应用快速开发指南
21OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
22OSGi.基于Spring,Hibernate的Web应用快速开发指南    public void remove(T entity) {
23OSGi.基于Spring,Hibernate的Web应用快速开发指南        getBaseDao().delete(entity);
24OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

25OSGi.基于Spring,Hibernate的Web应用快速开发指南
26OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
27OSGi.基于Spring,Hibernate的Web应用快速开发指南    public T getById(Serializable id) {
28OSGi.基于Spring,Hibernate的Web应用快速开发指南        return getBaseDao().findById(id);
29OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

30OSGi.基于Spring,Hibernate的Web应用快速开发指南
31OSGi.基于Spring,Hibernate的Web应用快速开发指南    protected abstract IBaseDao<T> getBaseDao();
32OSGi.基于Spring,Hibernate的Web应用快速开发指南}

33 OSGi.基于Spring,Hibernate的Web应用快速开发指南

f) 实现IUserService接口
src/com.dw.test.service.impl.UserServiceImpl.java

 1
OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.service.impl;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.beans.factory.annotation.Autowired;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.stereotype.Service;
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.transaction.annotation.Transactional;
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.dao.IBaseDao;
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.dao.IUserDao;
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.domain.User;
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.service.IUserService;
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南@Service( " userService " )
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南@Transactional
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   class  UserServiceImpl  extends  BaseServiceImpl < User >   implements
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南        IUserService  {
16OSGi.基于Spring,Hibernate的Web应用快速开发指南
17OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Autowired
18OSGi.基于Spring,Hibernate的Web应用快速开发指南    private IUserDao userDao;
19OSGi.基于Spring,Hibernate的Web应用快速开发指南
20OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Override
21OSGi.基于Spring,Hibernate的Web应用快速开发指南    public IBaseDao<User> getBaseDao() {
22OSGi.基于Spring,Hibernate的Web应用快速开发指南        return userDao;    
23OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

24OSGi.基于Spring,Hibernate的Web应用快速开发指南
25OSGi.基于Spring,Hibernate的Web应用快速开发指南}

26 OSGi.基于Spring,Hibernate的Web应用快速开发指南

g) 定义Spring Bean
src/META-INF/spring/appContext.xml
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns = " http://www.springframework.org/schema/beans "
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南    xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "  xmlns:aop = " http://www.springframework.org/schema/aop "
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南    xmlns:tx = " http://www.springframework.org/schema/tx "  xmlns:context = " http://www.springframework.org/schema/context "
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南    xsi:schemaLocation = " http://www.springframework.org/schema/beans
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/beans/spring-beans.xsd
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/context
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南         http: // www.springframework.org/schema/context/spring-context.xsd">
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < context:annotation - config  />
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南    
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < context:component - scan base - package = " com.dw.test "   />
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南
17 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < tx:annotation - driven transaction - manager = " transactionManager "   />
18 OSGi.基于Spring,Hibernate的Web应用快速开发指南
19 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < tx:advice id = " txAdvice "  transaction - manager = " transactionManager " >
20 OSGi.基于Spring,Hibernate的Web应用快速开发指南         < tx:attributes >
21 OSGi.基于Spring,Hibernate的Web应用快速开发指南             < tx:method name = "search * "  read - only = " true "   />
22 OSGi.基于Spring,Hibernate的Web应用快速开发指南             < tx:method name = " * "  rollback - for = " Exception "   />
23 OSGi.基于Spring,Hibernate的Web应用快速开发指南         </ tx:attributes >
24 OSGi.基于Spring,Hibernate的Web应用快速开发指南     </ tx:advice >
25 OSGi.基于Spring,Hibernate的Web应用快速开发指南    
26 OSGi.基于Spring,Hibernate的Web应用快速开发指南     < aop:config >
27 OSGi.基于Spring,Hibernate的Web应用快速开发指南         < aop:pointcut id = " serviceCut "  expression = " execution(* com.dw.test..service..*.*(..)) "   />
28 OSGi.基于Spring,Hibernate的Web应用快速开发指南         < aop:advisor pointcut - ref = " serviceCut "  advice - ref = " txAdvice "   />
29 OSGi.基于Spring,Hibernate的Web应用快速开发指南     </ aop:config >
30 OSGi.基于Spring,Hibernate的Web应用快速开发指南    
31 OSGi.基于Spring,Hibernate的Web应用快速开发指南    
32 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >
33 OSGi.基于Spring,Hibernate的Web应用快速开发指南

h) 定义OSGi bean
src/META-INF/spring/osgiContext.xml
OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
OSGi.基于Spring,Hibernate的Web应用快速开发指南
< beans xmlns = " http://www.springframework.org/schema/beans "
OSGi.基于Spring,Hibernate的Web应用快速开发指南    xmlns:xsi
= " http://www.w3.org/2001/XMLSchema-instance "  xmlns:osgi = " http://www.springframework.org/schema/osgi "
OSGi.基于Spring,Hibernate的Web应用快速开发指南    xmlns:context
= " http://www.springframework.org/schema/context "
OSGi.基于Spring,Hibernate的Web应用快速开发指南    xsi:schemaLocation
= " http://www.springframework.org/schema/beans
OSGi.基于Spring,Hibernate的Web应用快速开发指南
        http: // www.springframework.org/schema/beans/spring-beans.xsd
OSGi.基于Spring,Hibernate的Web应用快速开发指南
        http: // www.springframework.org/schema/osgi
OSGi.基于Spring,Hibernate的Web应用快速开发指南
        http: // www.springframework.org/schema/osgi/spring-osgi.xsd
OSGi.基于Spring,Hibernate的Web应用快速开发指南
        http: // www.springframework.org/schema/context
OSGi.基于Spring,Hibernate的Web应用快速开发指南
        http: // www.springframework.org/schema/context/spring-context.xsd">
OSGi.基于Spring,Hibernate的Web应用快速开发指南

OSGi.基于Spring,Hibernate的Web应用快速开发指南
OSGi.基于Spring,Hibernate的Web应用快速开发指南    
< osgi:reference id = " userDao "   interface = " com.dw.test.dao.IUserDao "   />
OSGi.基于Spring,Hibernate的Web应用快速开发指南    
OSGi.基于Spring,Hibernate的Web应用快速开发指南    
< osgi:reference id = " transactionManager "      interface = " org.springframework.transaction.PlatformTransactionManager "   />
OSGi.基于Spring,Hibernate的Web应用快速开发指南
OSGi.基于Spring,Hibernate的Web应用快速开发指南    
< osgi:service ref = " userService "   interface = " com.dw.test.service.IUserService "   />
OSGi.基于Spring,Hibernate的Web应用快速开发指南
OSGi.基于Spring,Hibernate的Web应用快速开发指南
</ beans >
OSGi.基于Spring,Hibernate的Web应用快速开发指南


5.7 com.dw.test.web

a) 创建bundle项目,名为com.dw.test.web,参考5.1 a(创建过程中记得勾选Web Application Bundle,源码编译输出目录设置为WEB-INF/classes)

b) 引入项目com.dw.test.domain,com.dw.test.service,参考5.3 b

c) 导入依赖包,com.dw.test.domain,com.dw.test.service,org.eclipse.virgo.web.dm,org.slf4j,参考5.1 b

d) 导入Hibernate bundle,参考5.4 d

e) 导入Spring库,参考5.4

f) 创建控制器
src/com.dw.test.web.controller.UserController.java
 1 OSGi.基于Spring,Hibernate的Web应用快速开发指南package  com.dw.test.web.controller;
 2 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  javax.annotation.Resource;
 4 OSGi.基于Spring,Hibernate的Web应用快速开发指南
 5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.slf4j.Logger;
 6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.slf4j.LoggerFactory;
 7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.stereotype.Controller;
 8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  org.springframework.web.bind.annotation.RequestMapping;
 9 OSGi.基于Spring,Hibernate的Web应用快速开发指南
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.domain.User;
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 import  com.dw.test.service.IUserService;
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南@Controller
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南@RequestMapping( " /user " )
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南 public   class  UserController  {
16OSGi.基于Spring,Hibernate的Web应用快速开发指南
17OSGi.基于Spring,Hibernate的Web应用快速开发指南    Logger logger = LoggerFactory.getLogger(UserController.class);
18OSGi.基于Spring,Hibernate的Web应用快速开发指南    
19OSGi.基于Spring,Hibernate的Web应用快速开发指南    @Resource
20OSGi.基于Spring,Hibernate的Web应用快速开发指南    private IUserService userService;
21OSGi.基于Spring,Hibernate的Web应用快速开发指南    
22OSGi.基于Spring,Hibernate的Web应用快速开发指南    @RequestMapping(value="/create")
23OSGi.基于Spring,Hibernate的Web应用快速开发指南    public String create(){
24OSGi.基于Spring,Hibernate的Web应用快速开发指南        logger.info("创建用户:");
25OSGi.基于Spring,Hibernate的Web应用快速开发指南        User user = new User();
26OSGi.基于Spring,Hibernate的Web应用快速开发指南        user.setUsername("osmos");
27OSGi.基于Spring,Hibernate的Web应用快速开发指南        user.setPassword("123456");
28OSGi.基于Spring,Hibernate的Web应用快速开发指南        userService.create(user);
29OSGi.基于Spring,Hibernate的Web应用快速开发指南        return null;
30OSGi.基于Spring,Hibernate的Web应用快速开发指南    }

31OSGi.基于Spring,Hibernate的Web应用快速开发指南}

32 OSGi.基于Spring,Hibernate的Web应用快速开发指南

g) 定义web配置
WEB-INF/web.xml
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 " encoding = " UTF-8 " ?>
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < web - app xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns = " http://java.sun.com/xml/ns/javaee " xmlns:web = " http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xsi:schemaLocation = " http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 id = " WebApp_ID " version = " 2.5 " >
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南
7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < display - name > test </ display - name >
8 OSGi.基于Spring,Hibernate的Web应用快速开发指南
9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < context - param >
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < param - name > webAppRootKey </ param - name >
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < param - value > test.root </ param - value >
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ context - param >
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < context - param >
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < param - name > contextClass </ param - name >
17 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < param - value > org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext </ param - value >
18 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ context - param >
19 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < listener >
20 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < listener - class > org.springframework.web.context.ContextLoaderListener </ listener - class >
21 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ listener >
22 OSGi.基于Spring,Hibernate的Web应用快速开发指南
23 OSGi.基于Spring,Hibernate的Web应用快速开发指南
24 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < servlet >
25 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < servlet - name > app </ servlet - name >
26 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < servlet - class > org.springframework.web.servlet.DispatcherServlet </ servlet - class >
27 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ servlet >
28 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < servlet - mapping >
29 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < servlet - name > app </ servlet - name >
30 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < url - pattern >/</ url - pattern >
31 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ servlet - mapping >
32 OSGi.基于Spring,Hibernate的Web应用快速开发指南
33 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ web - app >

h) 定义Spring MVC配置
WEB-INF/app-servlet.xml
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 " encoding = " UTF-8 " ?>
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns = " http://www.springframework.org/schema/beans "
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xmlns:p = " http://www.springframework.org/schema/p "
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:aop = " http://www.springframework.org/schema/aop " xmlns:context = " http://www.springframework.org/schema/context "
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:util = " http://www.springframework.org/schema/util " xmlns:mvc = " http://www.springframework.org/schema/mvc "
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:tx = " http://www.springframework.org/schema/tx "
7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xsi:schemaLocation = "
8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/beans
9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/beans/spring-beans.xsd
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context/spring-context.xsd
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/aop
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/aop/spring-aop.xsd
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/tx
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/tx/spring-tx.xsd
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/util
17 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/util/spring-util.xsd
18 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/mvc
19 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/mvc/spring-mvc.xsd">
20 OSGi.基于Spring,Hibernate的Web应用快速开发指南
21 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < context:component - scan base - package = " com.dw.test " />
22 OSGi.基于Spring,Hibernate的Web应用快速开发指南
23 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < bean class = " org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter " />
24 OSGi.基于Spring,Hibernate的Web应用快速开发指南
25 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < mvc:interceptors >
26 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < bean id = " openSessionInViewInterceptor "     class = " org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor " >
27 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " sessionFactory " ref = " sessionFactory " />
28 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ bean >
29 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ mvc:interceptors >
30 OSGi.基于Spring,Hibernate的Web应用快速开发指南
31 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < bean id = " viewResolver " class = " org.springframework.web.servlet.view.InternalResourceViewResolver " >
32 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " viewClass " value = " org.springframework.web.servlet.view.JstlView " />
33 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " prefix " value = " /WEB-INF/views/ " />
34 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < property name = " suffix " value = " .jsp " />
35 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ bean >
36 OSGi.基于Spring,Hibernate的Web应用快速开发指南
37 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >
38 OSGi.基于Spring,Hibernate的Web应用快速开发指南

i) 定义服务引用
WEB-INF/applicationContext.xml
1 OSGi.基于Spring,Hibernate的Web应用快速开发指南<? xml version = " 1.0 " encoding = " UTF-8 " ?>
2 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < beans xmlns = " http://www.springframework.org/schema/beans "
3 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xmlns:osgi = " http://www.springframework.org/schema/osgi "
4 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xmlns:context = " http://www.springframework.org/schema/context "
5 OSGi.基于Spring,Hibernate的Web应用快速开发指南 xsi:schemaLocation = " http://www.springframework.org/schema/beans
6 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/beans/spring-beans.xsd
7 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/osgi
8 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/osgi/spring-osgi.xsd
9 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context
10 OSGi.基于Spring,Hibernate的Web应用快速开发指南 http: // www.springframework.org/schema/context/spring-context.xsd">
11 OSGi.基于Spring,Hibernate的Web应用快速开发指南
12 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < osgi:reference id = " sessionFactory " interface = " org.hibernate.SessionFactory " />
13 OSGi.基于Spring,Hibernate的Web应用快速开发指南
14 OSGi.基于Spring,Hibernate的Web应用快速开发指南 < osgi:reference id = " userService " interface = " com.dw.test.service.IUserService " />
15 OSGi.基于Spring,Hibernate的Web应用快速开发指南
16 OSGi.基于Spring,Hibernate的Web应用快速开发指南 </ beans >
17 OSGi.基于Spring,Hibernate的Web应用快速开发指南
18 OSGi.基于Spring,Hibernate的Web应用快速开发指南

j) 注意事项
com.dw.test.web项目的MANIFEST.MF文件内容有如下头信息,否则会有无法访问以及注解无效等问题
Web-ContextPath: /test
Bundle-ClassPath: WEB-INF/classes