我在项目启动时遇到这样的错误:java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.context.request.ServletRequestAttributes
我使用Spring MVC + Hibernate,对于我使用Oracle Weblogic 12c的服务器。
这是我的pom.xml
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>3.2.13.RELEASE</spring.version>
<jstl.version>1.2</jstl.version>
</properties>
<dependencies>
<dependency>
<!-- Spring -->
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<!--
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion> -->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.18.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.18.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.5.RELEASE</version>
<type>jar</type>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.21.Final</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
这是我的web.xml
<web-app 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_2_5.xsd"
version="2.5">
<display-name>Spring3 MVC Application</display-name>
<servlet>
<servlet-name>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<!--
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-config.xml</param-value>
</init-param>
-->
</servlet>
<servlet-mapping>
<servlet-name>spring-web</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>
这是我的控制器
@Controller
@Transactional
public class HelloController {
@Autowired(required = true)
private SessionFactory sf;
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
return "index";
}
}
所以,当我开始我的程序时,它会将我发送到我已经形成的index.html
,并可以继续使用它。
答案 0 :(得分:0)
可能是因为您在spring组件中使用了不同的版本,尝试使用所有Spring依赖项的相同版本
答案 1 :(得分:0)
好的,老实说,我不知道问题是什么,但重新启动IDE和Clean Build可以帮助我处理它。