[英]Unable to run 2 Spring MVC Maven hibernate web apps in same tomcat server
我開始從事第二個Spring MVC maven休眠項目,並想重新使用現有的工作項目,因為它有很多類似的代碼,並且有理由不要完全從頭開始。
因此,我從使用Hibernate的現有Spring MVC項目中創建了一個Maven原型,但是我無法讓新的Web應用程序在同一tomcat服務器上工作。
該應用程序僅返回404錯誤,並且日志顯示以下錯誤,原因如下:java.io.FileNotFoundException:src \\ main \\ resources \\ database \\ hbm \\ bannerItem.hbm.xml(系統找不到指定的路徑)
現有應用仍然可以正常運行。
我已經嘗試了以下方法。
確保構建路徑正確並顯示資源文件夾
刪除並重新添加資源文件夾
刪除對bannerItem.hbm.xml的引用-清潔等-很奇怪,仍然報告了錯誤!
刪除創建的新原型項目,並簡單地復制現有項目並重命名項目屬性-只是為了排除原型創建方面的問題,但是原始問題仍然存在。
清除Maven存儲庫並重新下載所有庫,以防萬一有些損壞-這沒有什么區別。
從服務器配置中刪除了Web模塊並進行了清理-無數次-仍然沒有區別
在不同的工作空間,相同的工作空間,不同的tomcat實例中運行項目。
現在真的撞牆了,可以使用一些幫助。 我要提到的一件事是,我回想起類似的問題,當我刪除了Maven repo庫並從eclipse中重新下載它們時,似乎可以解決上述問題,但是由於某種原因,我的項目可以運行了,但是,jsp不會渲染。 我通過創建一個新的jsp並將舊的jsp代碼粘貼到新的jsp中來解決該問題,從而解決了該問題-絕對不知道為什么解決了該問題,但是確實如此-嘗試了此問題,但是沒有工作,因為它不能替代根本的“資源”問題。
希望有人可以在這里提供幫助...樂意附加所需的任何代碼
謝謝
完整的堆棧跟蹤/日志輸出太冗長而無法在此處粘貼,因此這里是輸出的第一和最后
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,謝謝-這是文件內容
<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>
映射文件
<?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>
您尚未正確提及文件路徑
src \\ main \\ resources \\ database \\ hbm \\ bannerItem.hbm.xml
在休眠配置文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.