问题1:org.springframework.beans.factory.NoSuchBeanDefinitionException:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
1)在web.xml中添加:
<!-- 解决Hibernate延迟加载问题 -->
<filter>
<filter-name>HibernateOpenSession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>mySessionFactory</param-value>
</init-param>
</filter>
2)在基础类中重写sessionFactory方法
// 使用注解方式进行依赖注入
@Resource
// @Autowired
// @Qualifier(value="abc")
public void setMySessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
问题2: javax.servlet.ServletException: Servlet.init() for servlet springMVC threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
3 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
4 org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
5 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
6 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
7 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
8 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
9 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
10 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
11 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
12 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
13 java.lang.Thread.run(Thread.java:745)
14
15 root cause
16
17 java.lang.IllegalArgumentException
18 org.springframework.asm.ClassReader.<init>(Unknown Source)
19 org.springframework.asm.ClassReader.<init>(Unknown Source)
20 org.springframework.asm.ClassReader.<init>(Unknown Source)
21 org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
22
解决办法:
一:把jdk版本换成1.7 or 1.7以下
1)打开eclipse后依次打开windows——》Preferences,打开属性窗口
2)在打开的preferences窗口的左边树形菜单中依次展开:java——》Compiler,如图
然后点击apply
原因:1.8版本与asm.jar不兼容
二:使用spring 4.0RELEASE及以上版本
问题3:applicationContext.xml
解决方法:
1)applicationContext.xml文件的位置放置
2)在web.xml中配置
<!-- 指定spring配置文件的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>