gpt4 book ai didi

Java Bean创建异常

转载 作者:行者123 更新时间:2023-12-01 12:28:53 25 4
gpt4 key购买 nike

我正在修改 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 文件:

<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>`

最佳答案

通常,当我看到 spring 错误时,我发现一直滚动到代码块最右侧消息行的末尾是最有用的......

我看到:

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

我猜测该类不在您的类路径中,但被您的 beans 配置中的某些内容引用。我还建议这条线看起来很可疑,可能意味着您还没有编辑某些内容,但它可能是特定于heroku的(例如您正在遵循的教程示例?),所以我对此无能为力:

for bean with name 'name of the object'

由于我在您提供的应用程序上下文中没有看到“对象名称”,因此似乎很可能正在加载其他一些应用程序上下文文件。

关于Java Bean创建异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26110370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com