当前位置: 代码迷 >> Java Web开发 >> sessionFactory注入有关问题
  详细解决方案

sessionFactory注入有关问题

热度:8599   发布时间:2016-04-10 22:46:11.0
sessionFactory注入问题
[color=#FF0000]我是java 新手,遇到点问题,请大家帮忙
sessionFactory注入总出错,我用的是struts2+spring3+hebernate4,下面是代码

web.xml[/color]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<filter>
<filter-name>openSessionInViewFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
  <init-param>
  <param-name>sessionFactoryBeanName</param-name>
  <param-value>sessionFactory</param-value>
  </init-param>
</filter>  

<filter-mapping>  
        <filter-name>openSessionInViewFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
</filter-mapping> 

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>

<!-- Log4j ConfigurationFile Location -->  
<context-param>  
    <param-name>log4jConfigLocation</param-name>  
    <param-value>classpath:log4j.properties</param-value>  
</context-param>  

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>/login/login.jsp</welcome-file>
</welcome-file-list>

<listener>
<listener-class>
    org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

</web-app>


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:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"
            default-autowire="byName" default-lazy-init="true">


   <!-- 数据源 -->   
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" scope="prototype"> 
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:sqlserver://JF:1433;DatabaseName=Extensiondatabase</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>123456</value>
</property>
    </bean>
    
<bean id="sessionFactory" name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="prototype">
 <property name="dataSource" ref="dataSource"></property>  
         <property name="hibernateProperties">  
         <props>  
          <prop key="hibernate.dialect">  org.hibernate.dialect.SQLServerDialect</prop>  
            <prop key="hibernate.show_sql">true</prop> 
  相关解决方案