Java BeanCreationException

时间:2014-09-29 23:14:46

标签: java spring hibernate spring-mvc

我正在从Heroku修改Java Spring Hibernate模板并尝试连接本地postgresql数据库。但是,我收到此错误,并且不确定如何修复它。

`org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.java.model.FirstModelImple] for bean with name 'name of the object' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.java.model.FirstModelImple
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.java.model.FirstModelImple] for bean with name 'name of the object' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.java.model.FirstModelImple
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.java.model.FirstModelImple] for bean with name 'name of the object' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.java.model.FirstModelImple
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    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$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    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:744)`

这是我的applicationContext.xml文件,我在其中声明了db:

<beans profile="default">
    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://ericsMac@localhost/mydb"/>
        <property name="username" value="ericsMac"/>
        <property name="password" value=" "/>
    </bean> 

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <!-- change this to 'verify' before running as a production app -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>
</beans>`

1 个答案:

答案 0 :(得分:1)

一般来说,当我看到弹簧错误时,我发现将所有方式(方式,方式,方式)滚动到代码块最右侧消息行末尾最有用...

我明白了:

java.lang.ClassNotFoundException: com.java.model.FirstModelImple

我猜测该类不在您的类路径中,而是由您的bean配置中的某些内容引用。我还建议这条线看起来很腥,可能意味着你没有编辑过某些东西,但它可能是特定的heroku(比如你正在关注的教程示例?)所以我无法帮助那个:

for bean with name 'name of the object'

因为我没有看到对象的名称&#39;在您提供的应用程序上下文中,似乎很可能某些其他应用程序上下文文件正在加载。