- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [clinic.ict.service.TestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:215)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:185)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:146)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:222)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:171)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:120)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:96)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [clinic.ict.service.TestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @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:901)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:685)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 37 more
代码如下:
TestController.java
package clinic.ict.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import clinic.ict.service.TestService;
@Controller
public class TestController {
@Autowired
@Resource
private TestService testService;
public TestService getTestService() {
return testService;
}
public void setTestService(TestService testService) {
this.testService = testService;
}
@RequestMapping(method=RequestMethod.GET,value="/clinic/{code}")
public ModelAndView displayData(HttpServletRequest request, HttpServletResponse response,@PathVariable("code") String clinicCode){
String returnedService = testService.getSomeServiceHere(clinicCode);
return new ModelAndView("Test", "argx", returnedService);
}
}
测试服务.java
package clinic.ict.service;
import org.springframework.stereotype.Service;
@Service
public interface TestService {
public String getSomeServiceHere(String clinicCode);
}
TestServiceImpl.java
package clinic.ict.serviceimpl;
import org.springframework.stereotype.Service;
import clinic.ict.service.TestService;
@Service
public class TestServiceImpl implements TestService{
@Override
public String getSomeServiceHere(String clinicCode){
return ("Returned Service to clinic "+clinicCode);
}
}
dispatcher-servlet.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"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="clinic.ict.controller">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:component-scan base-package="clinic.ict.service">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
</beans>
最佳答案
您正在对 service
包进行类路径扫描,但您的 TestService
接口(interface)的实现实际上在 serviceimpl
包中。
clinic.ict.serviceimpl
不是 clinic.ict.service
的子包;他们只是碰巧共享一个前缀。因此 serviceimpl
包不会被扫描,因此 Spring 不会自动为您实例化 TestServiceImpl bean。
关于java - BeanCreationException NoSuchBeanDefinitionException 在为以下 Spring 代码启动 Google App Server 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3464427/
我正在使用 grails cxf-Plugin,它在本地运行良好,但是当我将它部署在 tomcat 服务器上时出现错误: ERROR context.GrailsContextLoaderListen
这是 org.xml.sax.SAXParseException;cvc-complex-type.2.4.c: The matching wildcard is strict, but no dec
有人可以告诉我如何克服 BeanCreationException 吗? 将两个变量添加到 Owner.java 后,我收到 BeanCreationException如下: @OneToMany(c
我正在尝试使用 Spring 开发 RESTful Web 服务,然后将其部署在 Google App Engine 上。该服务的客户端将是一个 Android 应用程序。我是第一次使用 spring
2011-06-13 11:45:53,128 ERROR [org.springframework.web.context.ContextLoader] Context initialization
我正在尝试从 session 工厂获取 session 以用于我的 CRUD 方法。我试图在构造函数中设置 session ,但此时 bean 尚未初始化。创建 bean 后如何初始化它? 堆栈跟踪
我正在尝试在 glassfish 上部署 netbeans java ee 项目(maven + hibernate + JSF) 我在下面收到错误。我的数据库配置没问题(从多个应用程序仔细检查),并
我正在开始使用一个小型 Spring MVC 应用程序,当我运行服务器时,出现此错误,我不知道我做错了什么,我试图理解为什么 @Autowiring 不起作用: org.springframework
我正在使用 SpringBoot 开发 Spring 4 应用程序。 在com.test.tm包中, 应用类: @SpringBootApplication @EnableJpaRepositor
我正在设置一个 Spring Boot maven 多模块项目,其中包含域层、持久层和 Web 层。 我一直在查找类似的问题,但似乎没有一个是我的情况,我怀疑这是因为该项目被划分为单独的maven模块
我有一个在本地运行的项目,但是当我尝试将其部署到 tomcat 7 服务器时,出现以下异常: ERROR: [Feb-05 16:39:30,240] web.context.ContextLoade
我尝试在 Spring 应用程序中使用 Hibernate,但项目部署时出现错误 Exception while loading the app : java.lang.IllegalStateExc
我尝试使用 spring4 和 jackrabbit 开发一些服务器程序。当我使用 JUnit 测试 Controller 类时,发生 BeanCreationExceptrion 错误。我认为这个错
我正在研究STS数据库连接。 我尝试连接我的本地数据库。 我的HomeController.java: @Controller public class HomeController { @Autow
我的 bean 定义, 异常, Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
在启动过程中,我的应用程序创建了一个 bean,它在任务执行器中调度一些任务,然后在创建另一个 bean 后失败。这使我的应用程序处于不死状态,应用程序看起来正在运行但不提供功能。我想知道如何全局处理
我收到以下错误。谁能告诉我错误堆栈中的哪一行定义了我的错误? 2019-02-11 19:26:02.681 [main] ERROR o.s.web.context.ContextLoader -
我已经开始将 Spring MVC/Spring Web Tomcat 应用程序迁移到 Spring Boot。目前我正在将 xml 配置文件迁移到 java 配置。 当我尝试通过 mvn sprin
我在 Tomcat 上使用 Spring MVC。当我尝试启动 tomcat 时出现此异常: WARNING: Exception encountered during context initial
试图整合hibernate和spring,我遇到了这个错误 SEVERE: Context initialization failed org.springframework.beans.factor
我是一名优秀的程序员,十分优秀!