没有找到这样的Bean定义-Exception

时间:2014-04-24 17:19:52

标签: java spring hibernate spring-data-jpa

我有一个外部jar文件,它作为依赖项添加到另一个Web应用程序。当我独立运行这个Jar文件时,它可以正常工作。

当我在我的网络应用程序中包含此内容时,我收到以下错误

  

org.springframework.beans.factory.BeanCreationException:错误   创建名称为' inviteAuditService':注入资源的bean   依赖失败;嵌套异常是   org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   匹配类型的bean   [com.trunym.certificateserver.datajpa.repository.InviteAuditRepository]   找到依赖:预计至少有1个bean符合条件   autowire候选人这种依赖。依赖注释:   {@ javax.annotation.Resource(shareable = true,mappedName =,description =,   name =,type = class java.lang.Object,authenticationType = CONTAINER)} at   org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)     在   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)     在   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)     在   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)     在   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)     在   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)     在   org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139)     在   org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:93)     在   com.trunym.medallion.datajpa.factory.AbstractServiceFactory.getMedallionFactoryInstance(AbstractServiceFactory.java:14)     在   com.trunym.medallion.web.controller.ManageBadgeController.getHomePage(ManageBadgeController.java:27)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)at   org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)     在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)     在   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)     在   org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:820)at at   org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)     在   org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)     在   org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在   org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)     在   org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)     在   org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)     在   org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)     在   org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)     在   org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     在org.mortbay.jetty.Server.handle(Server.java:324)处   org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)     在   org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:829)     在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)at   org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)at at   org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)at at   org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)     在   org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:488)   引起:   org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   匹配类型的bean   [com.trunym.certificateserver.datajpa.repository.InviteAuditRepository]   找到依赖:预计至少有1个bean符合条件   autowire候选人这种依赖。依赖注释:   {@ javax.annotation.Resource(shareable = true,mappedName =,description =,   name =,type = class java.lang.Object,authenticationType = CONTAINER)} at   org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)     在   org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438)     在   org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)     在   org.springframework.context.annotation.CommonAnnotationBeanPostProcessor $ ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)     在   org.springframework.beans.factory.annotation.InjectionMetadata $ InjectedElement.inject(InjectionMetadata.java:150)     在   org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)     在   org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)     ......还有47个

以下是来自Web应用程序的应用程序上下文:

<import resource="classpath*:certificate-server-context.xml" />

<bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="false" />
        <property name="ignoreResourceNotFound" value="false" />
        <property name="locations">
            <list>
                <value>classpath:medallion-config.properties</value>
            </list>
        </property>
        <property name="placeholderPrefix" value="%{" />
        <property name="placeholderSuffix" value="}" />
    </bean>


    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
        <property name="order" value="1" />

    </bean>
    <bean id="velocityEngine"
        class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
        <property name="velocityProperties">
            <value>
                resource.loader=class
                class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
            </value>
        </property>
    </bean>
    <context:component-scan base-package="com.test.medallion.web.*" />
    <mvc:annotation-driven />
    <mvc:default-servlet-handler />
    <task:annotation-driven />

1 个答案:

答案 0 :(得分:1)

我设法解决了这个问题,问题是我的网络应用程序和外部jar中的包名称存在冲突。

上下文组件扫描正在解决问题。

谢谢, 阿布舍克巴克