如何在Spring mvc app中设置classpath?

时间:2015-05-07 08:31:00

标签: spring-mvc jboss7.x

我的服务器上有两个不同的网络应用程序。一个是Spring mvc app,另一个是struts app。这些应用程序的库位于不同的位置。以下是我的Spring mvc app结构:

enter image description here

Spring mvc app的所有jar文件都在WEB-INF/lib目录中。以下是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>My project</display-name>

    <servlet>
        <servlet-name>route</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>route</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

当我运行spring app时,它显示异常:

[org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-6) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.myproject.scm.dao.LoginDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/route-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;

但是当我在没有struts应用程序的情况下运行Spring mvc app时,运行正常。也许存在冲突的库?

我可以在Spring mvc应用程序中添加classpath,以便在适当的位置查看库jar吗?

1 个答案:

答案 0 :(得分:0)

JBoss 7附带Hibernate 3.如果你想使用Hibernate 4,你必须在你的jboss-deployment-structure中排除它。看看https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments有关隐式依赖的更多信息。