简体   繁体   English

无法在同一tomcat服务器中运行2个Spring MVC Maven休眠Web应用程序

[英]Unable to run 2 Spring MVC Maven hibernate web apps in same tomcat server

I started working on a 2nd Spring MVC maven hibernate project and wanted to re-use an existing working project as it had a lot of similar code and made sense not to start completely from scratch. 我开始从事第二个Spring MVC maven休眠项目,并想重新使用现有的工作项目,因为它有很多类似的代码,并且有理由不要完全从头开始。

So, i created a maven archetype from the existing working Spring MVC project which uses hibernate however i cannot get my new web app to work on the same tomcat server. 因此,我从使用Hibernate的现有Spring MVC项目中创建了一个Maven原型,但是我无法让新的Web应用程序在同一tomcat服务器上工作。

The app simply returns a 404 error and the logs show the following error Caused by: java.io.FileNotFoundException: src\\main\\resources\\database\\hbm\\bannerItem.hbm.xml (The system cannot find the path specified) 该应用程序仅返回404错误,并且日志显示以下错误,原因如下:java.io.FileNotFoundException:src \\ main \\ resources \\ database \\ hbm \\ bannerItem.hbm.xml(系统找不到指定的路径)

The existing app still works fine. 现有应用仍然可以正常运行。

I've tried the following.. 我已经尝试了以下方法。

  1. Ensuring the build path is correct and showing the resource folder 确保构建路径正确并显示资源文件夹

  2. Removing and re-adding the resource folder 删除并重新添加资源文件夹

  3. Removing the reference to bannerItem.hbm.xml - cleaning etc etc - weirdly enough the error is still reported ! 删除对bannerItem.hbm.xml的引用-清洁等-很奇怪,仍然报告了错误!

  4. Removing the new archetype created project and simply taking a copy of the existing project and renaming project attributes - just to rule out an issue with the archetype creation, however the original problem persists. 删除创建的新原型项目,并简单地复制现有项目并重命名项目属性-只是为了排除原型创建方面的问题,但是原始问题仍然存在。

  5. Clearing the maven repo and re-downloading all libs just in case of some corruption somehow - this makes no difference. 清除Maven存储库并重新下载所有库,以防万一有些损坏-这没有什么区别。

  6. Removed web modules from server configuration and cleaned - countless times - still no difference 从服务器配置中删除了Web模块并进行了清理-无数次-仍然没有区别

  7. Running project in difference workspace, same workspace, different tomcat instances. 在不同的工作空间,相同的工作空间,不同的tomcat实例中运行项目。

Really hit a brick wall now and could use some help. 现在真的撞墙了,可以使用一些帮助。 One thing i will mention is that i recall having a similar issue way back and when i removed the maven repo libs and re-downloaded them from within eclipse, it seemed to remove the issue above but then for some reason, my project would run, however jsp's would not render. 我要提到的一件事是,我回想起类似的问题,当我删除了Maven repo库并从eclipse中重新下载它们时,似乎可以解决上述问题,但是由于某种原因,我的项目可以运行了,但是,jsp不会渲染。 I got round that issue by creating a new jsp and pasting the old jsp code in to the the new jsp, which fixed the issue - absolutely no idea why this fixed the issue but it did - tried this for this problem but this doesn't work, in that it isn't replacing the root 'resource' problem. 我通过创建一个新的jsp并将旧的jsp代码粘贴到新的jsp中来解决该问题,从而解决了该问题-绝对不知道为什么解决了该问题,但是确实如此-尝试了此问题,但是没有工作,因为它不能替代根本的“资源”问题。

Hope someone can help here...happy to attach any code needed 希望有人可以在这里提供帮助...乐意附加所需的任何代码

Thanks 谢谢

The full stack trace / log output is too verbose to paste in here, so here is the first and last of the output 完整的堆栈跟踪/日志输出太冗长而无法在此处粘贴,因此这里是输出的第一和最后

16:31:59,271 ERROR [localhost-startStop-1] (ContextLoader.java:319) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bannerPageController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.stevebarnacle.site.services.BannerItemService com.stevebarnacle.site.common.controller.BannerPageController.bannerItemService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bannerItemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.stevebarnacle.site.dao.BannerItemDao com.stevebarnacle.site.services.impl.BannerItemServiceImpl.bannerItemDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bannerItemDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.stevebarnacle.site.dao.impl.AbstractDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database/hibernate.cfg.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: src\main\resources\database\hbm\bannerItem.hbm.xml (The system cannot find the path specified)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:663)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1642)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.stevebarnacle.site.services.BannerItemService com.stevebarnacle.site.common.controller.BannerPageController.bannerItemService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bannerItemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.stevebarnacle.site.dao.BannerItemDao com.stevebarnacle.site.services.impl.BannerItemServiceImpl.bannerItemDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bannerItemDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.stevebarnacle.site.dao.impl.AbstractDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database/hibernate.cfg.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: src\main\resources\database\hbm\bannerItem.hbm.xml (The system cannot find the path specified)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 27 more

....... .......

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database/hibernate.cfg.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: src\main\resources\database\hbm\bannerItem.hbm.xml (The system cannot find the path specified)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:891)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:834)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 55 more
Caused by: java.io.FileNotFoundException: src\main\resources\database\hbm\bannerItem.hbm.xml (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:125)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:297)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
    ... 65 more
01-Feb-2014 16:31:59 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart

@jb-nizet, thanks - here is the file content @ jb-nizet,谢谢-这是文件内容

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
               <!--  <value>classpath*:database/database.properties</value> -->
                <value>classpath:database/database.properties</value>
            </list>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.user}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>

        <property name="mappingLocations">
            <list>
                <value>classpath:database/hbm/bannerItem.hbm.xml</value>
                <value>classpath:database/hbm/fileMeta.hbm.xml</value> 

            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
       <!--  <property name="hbm2ddl.auto">create</property> -->
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

</beans>

Mapping file 映射文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping.dtd">

<hibernate-mapping>
    <class name="com.stevebarnacle.site.banner.BannerItem"
           table="bannerItem">
        <id name="bannerItemId" type="int">
            <column name="bannerItem_Id" />
            <generator class="native" />
        </id>
        <property name="bannerItemHyperTextLinkUrl" type="string">
            <column name="bannerItem_HyperTextLinkUrl" not-null="false" />
        </property>

        <property name="bannerItemHyperTextLinkText" type="string">
            <column name="bannerItem_HyperTextLinkText" not-null="false" />
        </property>

        <property name="bannerItemImageSourceUrl" type="string">
            <column name="bannerItemImageSourceUrl" not-null="false" />
        </property>

        <property name="bannerItemImageOverlayText" type="string">
            <column name="bannerItemImageOverlayText" not-null="false" />
        </property>

        <many-to-one name="imageFileMeta" column="IMAGEFILEMETA" class="com.stevebarnacle.site.file.ImageFileMeta" not-null="true" cascade="all" unique="false">
            <!-- <column name="imageFileMeta"  not-null="true" /> -->
        </many-to-one>

        <!-- <property name="createdOn" type="java.util.Date">
            <column name="createdOn" not-null="false" />
        </property> -->

    </class>
</hibernate-mapping>

you have not mentioned file path correctly for 您尚未正确提及文件路径

src\\main\\resources\\database\\hbm\\bannerItem.hbm.xml src \\ main \\ resources \\ database \\ hbm \\ bannerItem.hbm.xml

in the hibernate config file. 在休眠配置文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM