我知道这个问题已经被问了很多次了,但我真的很难找到正确的解决方法。我已经尝试了这么多的东西,看到这些问题,但似乎没有一个符合我的情况。
完整日志错误如下:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-20 12:28:25.613 ERROR 10152 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field dashboardService in com.timmi.springBoot.controllers.RestEndPoints required a bean of type 'com.timmi.springBoot.service.DashboardService' that could not be found.
Action:
Consider defining a bean of type 'com.timmi.springBoot.service.DashboardService' in your configuration.
[WARNING]
java.lang.reflect.InvocationTargetException
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:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restEndPoints': Unsatisfied dependency expressed through field 'dashboardService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.timmi.springBoot.service.DashboardService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.timmi.springBoot.controllers.Application.main(Application.java:20)
... 6 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.timmi.springBoot.service.DashboardService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)
... 25 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
以下是我当前的实现:
SpringBootApplication:
@SpringBootApplication
@EnableJpaRepositories(basePackages="com.timmi.springBoot.repositories")
@EntityScan(basePackages="com.timmi.springBoot.entities")
@EnableAutoConfiguration
@ComponentScan(basePackages="com.timmi.springBoot.service")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// TODO Auto-generated method stub
return super.configure(builder);
}
}
@RestController
@RequestMapping("/app")
public class RestEndPoints {
@Value("${default.course.name}")
private String cName;
@Value("${default.course.chapterCount}")
private int chaptersCount;
@Autowired
private CourseConfiguration courseConfiguration;
@Autowired
private DashboardService dashboardService;
@RequestMapping("/employees")
public List<EmployeeInformation> getAllEmpl(){
return dashboardService.getAllEmployee();
}
}
DashboardService接口:
public interface DashboardService{
List<CompanyRevenue> getTodayRevenueDash();
List<ProductCategory> getBestCategory();
List<OrderRecieved> getAllOrderRecieved();
List<OrderCollectionStatus> getOrderCollection();
List<EmployeeInformation> getAllEmployee();
void addEmployee(EmployeeInformation employeeInformation);
EmployeeInformation updateEmployee(EmployeeInformation employeeInformation);
void deleteEmployee(EmployeeInformation employeeInformation);
}
类服务:
@Service
public class DashboardServiceImpl implements DashboardService{
@Autowired
private CompanyRevenueRepository companyRevenueRepository;
@Autowired
private EmployeeInformationRepository employeeInformationRepository;
@Autowired
private OrderCollectionStatusRepository OrderCollectionStatusRepository;
@Autowired
private OrderRecievedRepository orderRecievedRepository;
@Autowired
private ProductCategoryRepository productCategoryRepository;
@Override
public List<CompanyRevenue> getTodayRevenueDash() {
return companyRevenueRepository.findAll();
}
@Override
public List<ProductCategory> getBestCategory() {
return productCategoryRepository.findByBestCategory(true);
}
@Override
public List<OrderRecieved> getAllOrderRecieved() {
return orderRecievedRepository.findAll();
}
@Override
public List<OrderCollectionStatus> getOrderCollection() {
return OrderCollectionStatusRepository.findAll();
}
@Override
public List<EmployeeInformation> getAllEmployee() {
return employeeInformationRepository.findAll();
}
@Override
public void addEmployee(EmployeeInformation employeeInformation) {
employeeInformationRepository.save(employeeInformation);
}
@Override
public EmployeeInformation updateEmployee(EmployeeInformation employeeInformation) {
return employeeInformationRepository.save(employeeInformation);
}
@Override
public void deleteEmployee(EmployeeInformation employeeInformation) {
employeeInformationRepository.delete(employeeInformation);
}
}
从DashboardService
中删除@repository
和@qualifier
;从DashboardServiceImpl
中删除@component
请熟悉这些注释:Spring中的@Component、@Repository和@Service注释有什么区别?
以下是例外情况: 我的代码: 我评论了setCacheable(true),因为它给出了一个错误。有人能帮忙吗?
正在尝试测试我的。。。编译器请求注入,但在为创建bean后,它返回通过字段 代码: 错误:
我有以下代码和结构。我得到以下错误,这是很长的错误消息。 创建名称为'departmentController'的bean时出错:通过字段'departmentService'表示的不满意的依赖项;嵌套异常org.springframework.beans.factory.不满意依赖异常: 实体类 存储库接口 服务等级 控制器类 主课 项目结构 完整错误堆栈跟踪:
无法解决测试Spring Boot应用程序的问题: 主控制器: 应用程序属性:
大家好,每个人都是spring的新手,正在尝试为CRUD创建一个简单的应用程序,但是我得到了下面的错误。我正在使用STS 创建名为“Client ServiceImpli”的bean时出错:通过字段“Client Repository”表示的不满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“clie