AppFuse + wicket:没有类型为[org.hibernate.SessionFactory]的合格bean [英] AppFuse + wicket: No qualifying bean of type [org.hibernate.SessionFactory]

查看:70
本文介绍了AppFuse + wicket:没有类型为[org.hibernate.SessionFactory]的合格bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用AppFuse(多模块项目)编写的小应用程序.我想尝试使用Apache Wicket制作某种UI.由于AppFuse基于Spring,因此我找到了教程一起使用Spring和Wicket.我在检票"页面中使用快速入门设置了Wicket项目. 每当我尝试运行Wicket应用程序时,都会出现此错误(完整的堆栈跟踪位于文章结尾):

I have a small application written in AppFuse (multi-modular project). I want to try to use the Apache Wicket to make some kind of UI. Since AppFuse is based on Spring I found a tutorial for using Spring and Wicket together. I setted up the Wicket project using quickstart from the Wicket page. Whenever I try to run the Wicket app I get this error (full stack trace is at the end of the post):

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'personClubDao': 
Injection of resource dependencies failed; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency.

这是我的AppFuse项目结构

Here is my AppFuse project structure

Hello (pom)
+--core (jar) - generated by AppFuse
   +--org.microapp.hello.model
   +--org.microapp.hello.dao
+--web (war)- generated by Appfuse
   +--org.microapp.hello.service
+--wicket (war)- Wicket application
   +--org.microapp.hello

核心模块中有四个实体-俱乐部房屋 PersonClub .用于人员,俱乐部和房屋的DAO在core/src/main/resources/applicationContext.xml中注册(如此处),而PersonClub实体的DAO位于org.microapp.hello.dao.PersonClubDaoHibernate.java中.

There are four entities in the core module - Person, Club, House and PersonClub. DAOs for Person, Club and House are registered in core/src/main/resources/applicationContext.xml (as shown here) and DAO for PersonClub entity is in org.microapp.hello.dao.PersonClubDaoHibernate.java.

这是 PersonClubDao 界面:

public interface PersonClubDao extends GenericDao<PersonClub, Long> {
    //some methods
}

这是 PersonClubDaoHibernate 类:

@Repository("personClubDao")
public class PersonClubDaoHibernate extends
    GenericDaoHibernate<PersonClub, Long> implements PersonClubDao {

    public PersonClubDaoHibernate() {
        super(PersonClub.class);
        // TODO Auto-generated constructor stub
    }

    //some methods
}

我现在要做的是,在wicket模块的 HomePage 类中自动连接PersonClubDao(或任何其他DAO),并显示数据库中的一些数据.

What I'm trying to do now, is to autowire PersonClubDao (or any other DAO) in HomePage class in wicket module and display some data from the database.

这是主页类:

public class HomePage extends WebPage {
    private static final long serialVersionUID = 1L;

    @SpringBean
    private PersonClubDao personClubDao;

    public HomePage(final PageParameters parameters) {
        super(parameters);
        // TODO Add your page's components here
        //no code here so far
    }
}

和检票口/src/main/webapp/WEB-INF/applicationContext.xml

and the wicket/src/main/webapp/WEB-INF/applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="org.microapp.hello.dao" />    

</beans>

如果我尝试制作一些虚拟接口和虚拟类,并使用@SpringBean对其进行连线,则可以正常工作.但是,当我尝试连接任何DAO时,应用程序崩溃.我不太确定该怎么做,我试图将休眠包的依赖项添加到我的pom.xml中,但是如果没有运气和谷歌搜索也无济于事.

If I try to make some dummy interface and dummy class and wire it using @SpringBean, it works just fine. But when I try to wire any of my DAOs, the application crashes. I'm not quite sure what to do, I tried to add dependecies for hibernate packages into my pom.xml, but without luck and googling also didn't help.

这是完整的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personClubDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:296)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:365)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:163)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at org.eclipse.jetty.maven.plugin.JettyServer.doStart(JettyServer.java:73)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:534)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:357)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:167)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:508)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
... 65 more

推荐答案

问题在您的中进行了描述,请参见

The problem is described in your the, see

未找到类型为[org.hibernate.SessionFactory]的合格Bean : 期望至少有1个可以成为此依赖项的自动装配候选者的bean.

No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

这意味着您尚未配置休眠 SessionFactory ,有关如何使用Spring创建SessionFactory的示例,请参见

That means you haven't configurated hibernate SessionFactory, google an example how to create SessionFactory using Spring, see

http://docs.spring. io/spring/docs/current/spring-framework-reference/html/orm.html

如果使用Hibernate,则需要在Spring上下文中创建其他一些bean.

If you use Hibernate it requires to create some other beans in the Spring context.

这篇关于AppFuse + wicket:没有类型为[org.hibernate.SessionFactory]的合格bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆