我使用hibernate 3.2.7和spring 3.2.8。错误是***
**“:创建ServletContext资源[/WEB-INF/Spring-Servlet.xml]中定义的名称为'session Factory'的bean时出错:init方法调用失败;嵌套异常为java.io.FileNotFoundException:ServletContext资源[/resources/hibernate.cfg.xml]无法解析为URL,因为它不存在”。
> org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'sessionFactory' defined in ServletContext
> resource [/WEB-INF/spring-servlet.xml]: Invocation of init method
> failed; nested exception is java.io.FileNotFoundException:
> ServletContext resource [/resources/hibernate.cfg.xml] cannot be
> resolved to URL because it does not exist at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
> at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
> at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
> at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
> at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
> at
> org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
> at
> org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
> at
> org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
> at
> org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
> at
> org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
> at
> org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
> at javax.servlet.GenericServlet.init(GenericServlet.java:158) at
> org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
> at
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
> at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
> 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:632)
> at
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:670)
> at
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
> at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
> at java.util.concurrent.FutureTask.run(FutureTask.java:262) at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> at java.lang.Thread.run(Thread.java:745) Caused by:
> java.io.FileNotFoundException: ServletContext resource
> [/resources/hibernate.cfg.xml] cannot be resolved to URL because it
> does not exist at
> org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)
> at
> org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBe
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.xhtml</value>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>resources/hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="10000000" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
>
LocalSessionFactoryBean
的ConfigLocation
属性为resource
类型,您可以使用前缀指定资源类型,例如:
classpath:resources/hibernate.cfg.xml
默认情况下,在ServletContext中,如果不指定前缀,资源将使用类ServletContextResource
。来自Spring文档:
5.3.4 ServletContextResource
您可以在spring文档的参考资料中看到所有的abaout资源。
http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/
我的如下所示,用于初始化持久性单元: 并抛出异常: 上下文初始化过程中遇到异常-取消刷新尝试:org.springframework.beans.factory.beanCreationException:创建类路径资源[com/myapp/appconfig.class]中定义的名称为“会话工厂”的bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.
问题内容: 问题: 我正在为在类中执行方法创建切入点。该类是控制器类,由注解@Controller表示,因此对于方面所要求的相同,不需要bean。我附加了dispathcher servlet代码,方面和控制器类。有人可以识别出问题所在。 DISPATCHER SERVLET : 方面: 控制器类别: 控制台错误: 问题答案: 这是Spring AOP中的限制。当你使用AspectJ切入点将方面编
更多的细节: 我正在尝试创建第一个没有注释的Spring MVC应用程序。下面是我的URL请求'http://localhost:8080/firstspringmvc/welcome.html',它调用了我的代码。 以下是我的错误列表供参考:
我正在做项目的Spring启动...但是得到了这个错误,而运行应用程序。这可能是H2数据库错误。但是要解决这个错误localhost应该运行,但程序在部署前终止...所以我不能看到什么是实际问题。 错误:org.springframework.beans.factory.BeanCreationException:创建名称为'project TaskRepository'的bean时出错com.a
目前正在努力部署WAR8.5中的war文件,但每次我启动我的war文件时,都会出现一个错误。 初始化上下文时捕获异常:{0}org.springframework.beans.factory.beanCreationException:创建ServletContext资源[/web-inf/my-servlet.xml]中定义的名为“Entity ManagerFactory”的bean时出错:调