搞了两天的东西原来只有几行代码,就解决问题了,真是让自己啼笑皆非。折腾了1天之久,不想后面的朋友继续走上我的错误之路,把过程给贴出来。
1、添加struts2&&hibernate3.2&&spring2.5 所需jar包,注意还要添加struts2-spring-plugin-2.1.8.1.jar。
2、删除冲突asm2.23.jar
3、添加jdbc驱动.jar添加到 %tomcat%/lib 下
4、修改%tomcat%/cfg/context.xml文件在<Context>中添加
5、在WEB-INF/web.xml中添加
6、最后就是配置spring数据源与sessionFacotry
至此,配置完成!
本人犯的错误,在main函数中调用ClassPathXMLApplicationContext获得bean,结果总是获取不到,并且报错,具体Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
容易犯的错误2: jdbc之类的错误,注意配置jndiName前后一致,并且java:comp/env/%jndiName%