session actory null-springmvc sessionFactory is null

问题描述

springmvc sessionFactory is null
严重: Servlet.service() for servlet [spring2] in context with path [/Lbl] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException

说明:@resource和@annotional都不起作用。
网上的方法都试过了,不起作用
spring2-servlet.xml

<?xml version=""1.0"" encoding=""UTF-8"" ?>
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:p=""http://www.springframework.org/schema/p""
xmlns:context=""http://www.springframework.org/schema/context""
xmlns:mvc=""http://www.springframework.org/schema/mvc""
xmlns:oxm=""http://www.springframework.org/schema/oxm""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"">

<context:component-scan base-package=""com.lbl.active"" /><bean class=""org.springframework.web.servlet.view.BeanNameViewResolver""/><bean id=""bookXmlView"" class=""org.springframework.web.servlet.view.xml.MarshallingView"">    <constructor-arg>        <bean class=""org.springframework.oxm.xstream.XStreamMarshaller"">            <property name=""autodetectAnnotations"" value=""true""/>        </bean>    </constructor-arg></bean><bean id=""jsonView"" class=""org.springframework.web.servlet.view.json.MappingJacksonJsonView""></bean>

application.xml

context:annotation-config/
<!-- 自动扫描与装配 -->
/context:component-scan

<!-- 导入外部的properties--> <context:property-placeholder location=""classpath:jdbc.properties""/> <!--配置session工厂 --><bean id=""sessionFactory"" class=""org.springframework.orm.hibernate3.LocalSessionFactoryBean""><!-- 配置数据库路径 classpath:WEB-INFclasseshibernate.cfg.xml-->    <property name=""configLocation"" value=""classpath:hibernate.cfg.xml""></property>     <!-- 配置数据库c3p0连接池  dataSource写错导致bean创建异常错误信息属性值设置错误 -->    <property name=""dataSource"" >  <!-- dataSouce应该写成dataSource第三个错误 -->    <bean class=""com.mchange.v2.c3p0.ComboPooledDataSource"">      <!-- 配置数据库信息 -->   <property name=""jdbcUrl"" value=""${jdbcUrl}""></property>   <property name=""driverClass"" value=""${driverClass}""></property>   <property name=""user"" value=""${user}""></property>   <property name=""password"" value=""${password}""></property>    <!-- 其他配置 -->    </bean></property></bean>  <!-- 配置声明事物管理  采用注解方式--> <bean id=""txManager"" class=""org.springframework.orm.hibernate3.HibernateTransactionManager"" >    <property name=""sessionFactory"" ref=""sessionFactory""></property> </bean>   <tx:annotation-driven transaction-manager=""txManager""/>

web.xml

<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns=""http://java.sun.com/xml/ns/javaee""
xsi:schemaLocation=""http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"" version=""3.0"">
Lbl

index.jsp

contextConfigLocation

/WEB-INF/applicationContext.xml

org.springframework.web.context.ContextLoaderListener

encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8

encodingFilter
*.do

   <filter>   <filter-name>openSession</filter-name>  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param>     <param-name>sessionFactoryBeanName</param-name>     <param-value>sessionFactory</param-value> </init-param>  </filter>  <filter-mapping>  <filter-name>openSession</filter-name>  <url-pattern>/*</url-pattern>  </filter-mapping>

spring2
org.springframework.web.servlet.DispatcherServlet
1

spring2
/

出错的类

@Transactional
public class DaoService implements DaoLbl{

@Resource
private SessionFactory sessionFactory;
private Class clazz;

@SuppressWarnings(""unchecked"")
public DaoService(){
System.out.println(""---1---->>>:""+this.getClass());
// System.out.println(""----2--->>>:""+this.getClass().getGenericSuperclass());
//使用反射技术获得 T的真实类型
ParameterizedType pt=(ParameterizedType)this.getClass()//
.getGenericSuperclass();//获取当前new的泛型父类类型
System.out.println(""------->:"");
this.clazz=(Class)pt.getActualTypeArguments()[0];
//获取第一个参数的实际类型
System.out.println(""class--->"" + clazz);
}

 protected Session getSession(){

//

// String path=""C:/Users/admin/workspace/Lbl/WebContent/WEB-INF/applicationContext.xml"";
// ApplicationContext ac=new FileSystemXmlApplicationContext(path);
// SessionFactory sessionFactory=(SessionFactory)ac.getBean(""sessionFactory"");
// System.out.println(""00001113333333----000->""+ sessionFactory);
// System.out.println(""00001113333333----000->""+ sessionFactory.openSession());

// return sessionFactory.openSession();
// System.out.println(""0000000->""+ sessionFactory.getCurrentSession());
try {
return sessionFactory.getCurrentSession();
} catch (Exception e) {
e.getStackTrace();
}
return null;

    }

}

解决方案

@Transactional
@Service-------少了这个吧
public class DaoService implements DaoLbl

解决方案二:
不行呀,DaoService类的jdk事物代理机制不起作用

解决方案三:
谁能帮我调试一下代码

解决方案四:
qq1339665152

解决方案五:
http://blog.csdn.net/evankaka/article/details/45790533

时间: 2024-09-20 00:43:30

session actory null-springmvc sessionFactory is null的相关文章

hibernate进行分页时,sessionFactory为null报空指针异常

问题描述 hibernate进行分页时,sessionFactory为null报空指针异常 从网上查了许都,都没能解决,不知道是配置文件有问题,还是方法写的有问题 解决方案 dao层实现类: /** @ClassName: BaseDaoImpl @Description: 基础dao实现 @author john @date 2015年2月26日 下午3:27:15 */ @SuppressWarnings("unchecked") public abstract class Bas

java-关于spring+hibernate 注入sessionFactory为null的问题

问题描述 关于spring+hibernate 注入sessionFactory为null的问题 最近一个项目需要用到struts2+spring+hibernate组合框架,我在一点一点的做配置,但做到注入SessionFactory时,一直不成功,在网上搜的一些解决方案也都不适用.故在此发布,希望高手们不吝赐教.web.xml的配置为: <?xml version=""1.0"" encoding=""UTF-8""

spring mvc-表单传递参数,springmvc 参数为null

问题描述 表单传递参数,springmvc 参数为null 前台我用一个表单Post提交,如下 window.location="./roleView"; //获得表单id提交 document.getElementById("searchFormId").submit(); 后台 springmvc 接不到表单传递的值 解决方案 看看contorl里面注入是否有问题 解决方案二: 看看name与后台接值是否一致

oracle中IS NULL和IS NOT NULL使用方法

当字符串为空时,在where 使用 is null来判断. 例子: create table test (    stuno number(10) primary key,    stuname varchar2(50) ) insert into test(stuno) values(10) insert into test(stuno,stuname) values(11,' ') select * from test where stuname is null才会取到所有值. 而selec

SQL SERVER 中is null 和 is not null 将会导致索引失效吗?

   其实本来这个问题没有什么好说的,今天优化的时候遇到一个SQL语句,因为比较有意思,所以我截取.简化了SQL语句,演示给大家看,如下所示 declare @bamboo_Code varchar(3);   set @bamboo_Code='-01';     SELECT DISTINCT yarn_lot FROM   dbo.rsjob WITH ( nolock ) WHERE  RIGHT(ges_no, 3) = @bamboo_Code        AND Isnull(y

null !=str 和 str !=null 两者有什么区别?

问题描述 Stringstr="";if(null!=str){System.out.println("空");}if(str!=null){System.out.println("空");}请问两种写法有什么区别? 解决方案 解决方案二:null!=str这种写法永远不会出现空指针异常.也是极限编程建议的写法解决方案三:同楼上,以前也有过相同的贴解决方案四:习惯不同解决方案五:引用1楼sotom的回复: null!=str 这种写法永远不会出现

重构——40引入Null对象(Introduce Null Object)

引入Null对象(Introduce Null Object) 你需要再三检查某对象是否为null:将null值替换为null对象 一.动机 1.多态最根本的好处在于:你不必在向对象询问"你是什么类型"而后根据得到的答案调用对象的某个行为--你只管调用就是了,其它的一切多态机制会为你安排妥当 2.null对象一定是常量,可以使用Singleton来实现它们 3.关于Null对象模式,你可以在Woolf[Woolf]中找到更详细的介绍 二.做法 1.为源类建立一个子类,使其行为就像是源类

null问题-target is null for setProperty(null, &amp;amp;quot;JGrade&amp;amp;quot;, [Ljava.lang.String;@578dfb)

问题描述 target is null for setProperty(null, "JGrade", [Ljava.lang.String;@578dfb) 错误描述: Error setting value ognl.OgnlException: target is null for setProperty(null, "JGrade", [Ljava.lang.String;@578dfb) at ognl.OgnlRuntime.setProperty(Og

Extjs4---Cannot read property &amp;#39;addCls&amp;#39; of null 或者 el is null 关于tab关闭后再打开不显示或者报错

做后台管理系统时遇到的问题,关于tab关闭后再打开不显示,或者报错 我在新的tabpanel中加入了一个grid,当我关闭再次打开就会报错Cannot read property 'addCls' of null, 原因是我在定义grid的错误 这是错误代码:   [javascript] view plaincopy   Ext.define('HT.view.Grid',{       extend:'Ext.grid.Panel',          title : '人员列表',