日期:2014-05-18  浏览次数:20666 次

s2sh整合,注解,sessionFactory问题
我使用了ssh2来整合,并且想达到零配置的目的,不要xml中写bean,也不要hibernate的实体与表的映射文件。
于是我打算使用spring的注解,和hibernate的注解来实现.
struts2+spring这里省去.
applicationContext.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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:component-scan base-package="com.gy_center"></context:component-scan>   
<!-- 连接SQL Server-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://localhost:1433;databaseName=gycenter">
</property>
<property name="username" value="sa" />
<property name="password" value="icenter" />
<property name="maxActive" value="300" />
<property name="maxWait" value="300" />
</bean>

<!-- session工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
 <ref local="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan"><!--配置扫描实体po-->
<list>
<value>com.gy_center.model</value>
</list>
</property>
</bean>

<!-- 事务管理器-->