右键项目 MyEclipse->Add Spring Capabilities……
下一步 选择Sping 2.5 Core Librarise 、ring 2.5 Persistence Core Librarise、pring 2.5 Web Libraries
下一步 选择applicationContext.xml的路径
下一步 创建sessionFactory 但是我那个没有这一项不知道为什么,谁知道怎么回事
打开 applicationContext.xml中添入sql 邦定
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<property name="url"
value="jdbc:microsoft:sqlserver://192.168.1.222:1433;databaseName=gs_oadb" />
<property name="username" value="sa" />
<property name="password" value="111111" />
</bean>
</beans>
我这段不好使
<bean id="sessinoFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="datasource">
<ref bean="datasource"/>
</property>
<property name="hibernatepropertise">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/oa/User.hbm.xml
</value>
</list>
</property>
</bean>
在web.xml中添加
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>/WEB-INF/applicationcontext*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.comtextloaderlistener
</listener-class>
</listener>
<filter>
<filter-name>lazyloadingfilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.opensessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyloadingfilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
修改,那个sessionFactory我找到原因了,就是把引用sessionFactory那个语句放datasource上面就好用了,哈哈
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
destroy-method="destroy">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>mapping.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SybaseDialect
</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</prop>
</props>
</property>
<!--<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
-->
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" >
<value>com.sybase.jdbc2.jdbc.SybDriver</value>
</property>
<property name="url"
value="jdbc:microsoft:sqlserver://192.168.1.222:1433;databaseName=gs_oadb" />
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>111111</value>
</property>
</bean>
<bean id="UserDao" class="com.oa.emap.dao.hibernate.UserDAoHibernate">
</bean>