简体   繁体   English

考虑在您的配置中定义“com.project.airCompanies.repo.AirCompanyRepository”类型的 bean。 带MySQL数据库

[英]Consider defining a bean of type 'com.project.airCompanies.repo.AirCompanyRepository' in your configuration. With MySQL database

It is my class where I implements airCompaniesService and override some methods:这是我的 class ,我在其中实现了 airCompaniesService 并覆盖了一些方法:

package com.project.airCompanies.service.impl;

import com.project.airCompanies.mapper.AirCompanyMapper;
import com.project.airCompanies.model.AirCompany;
import com.project.airCompanies.model.request.AirCompanyRequest;
import com.project.airCompanies.model.response.AirCompanyResponse;
import com.project.airCompanies.repo.AirCompanyRepository;
import com.project.airCompanies.service.AirCompanyService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AirCompanyServiceImpl implements AirCompanyService {
    private final AirCompanyRepository repo;
   
    private final AirCompanyMapper mapper;
    @Override
    public AirCompanyResponse save(AirCompanyRequest request) {
        AirCompany result = mapper.requestToModel(request);
        result = repo.save(result);
        return mapper.modelToResponse(result);

    }

    @Override
    public void delete(Integer id) {
        repo.deleteById(id);
    }
}

It is interface repository, where I created MySql Repository它是接口存储库,我在其中创建了 MySql 存储库

package com.project.airCompanies.repo;

import com.project.airCompanies.model.AirCompany;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AirCompanyRepository extends JpaRepository<AirCompany, Integer> {

}

And I have error:我有错误:

2021-03-04 12:07:58.439  INFO 7924 --- [  restartedMain] c.p.a.AirCompaniesApplication            : Starting AirCompaniesApplication using Java 15.0.1 on DESKTOP-2S6243E with PID 7924 (D:\TaskSynergyWay\airCompanies\target\classes started by natal in D:\TaskSynergyWay\airCompanies)
2021-03-04 12:07:58.443  INFO 7924 --- [  restartedMain] c.p.a.AirCompaniesApplication            : No active profile set, falling back to default profiles: default
2021-03-04 12:07:58.486  INFO 7924 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-03-04 12:07:58.486  INFO 7924 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-03-04 12:07:59.235  INFO 7924 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-03-04 12:07:59.242  INFO 7924 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-03-04 12:07:59.242  INFO 7924 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-03-04 12:07:59.302  INFO 7924 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-03-04 12:07:59.302  INFO 7924 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 815 ms
2021-03-04 12:07:59.331  WARN 7924 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'airCompaniesController' defined in file [D:\TaskSynergyWay\airCompanies\target\classes\com\project\airCompanies\controller\AirCompaniesController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'airCompanyServiceImpl' defined in file [D:\TaskSynergyWay\airCompanies\target\classes\com\project\airCompanies\service\impl\AirCompanyServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.project.airCompanies.repo.AirCompanyRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2021-03-04 12:07:59.334  INFO 7924 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-03-04 12:07:59.345  INFO 7924 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-04 12:07:59.360 ERROR 7924 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.project.airCompanies.service.impl.AirCompanyServiceImpl required a bean of type 'com.project.airCompanies.repo.AirCompanyRepository' that could not be found.


Action:

Consider defining a bean of type 'com.project.airCompanies.repo.AirCompanyRepository' in your configuration.


Process finished with exit code 0

So how I can solve this problem Consider defining a bean of type 'com.project.airCompanies.repo.AirCompanyRepository' in your configuration.那么我该如何解决这个问题考虑在你的配置中定义一个'com.project.airCompanies.repo.AirCompanyRepository'类型的bean。 With MySQL database?用 MySQL 数据库?

You have to make sure that your Components are searched by spring.您必须确保 spring 搜索到您的组件。 If you structure is as follow如果你的结构如下

ROOT
----com.example
---------------services            
---------------repositories
---------------controllers
---------------models
---------------configs
----ApplicationMain.java

Then you may not require to manually inform spring to search for component classes otherwise you can do那么您可能不需要手动通知 spring 搜索组件类,否则您可以这样做

@ComponentScan({"com.project.airCompanies.service", "com.project.airCompanies.repo"})

to your SpringBootApplication class Documentation到您的SpringBootApplication class 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序未运行,“考虑在您的配置中定义一个类型的 bean。” - Application not running, ''Consider defining a bean of type in your configuration." 考虑在您的配置中定义“io.ipl.amaresh.data.JobCompletionNotificationListener”类型的 bean。 那个豆子找不到 - Consider defining a bean of type 'io.ipl.amaresh.data.JobCompletionNotificationListener' in your configuration. The bean could not be found in that 考虑在您的配置中定义类型为“ com.face.ImageRepository”的bean? - Consider defining a bean of type 'com.face.ImageRepository' in your configuration? 考虑在您的配置中定义“com.fsse2207.project_backend.service.ProductService”类型的 bean - Consider defining a bean of type 'com.fsse2207.project_backend.service.ProductService' in your configuration 考虑在您的配置中定义类型为“com.repository.UserRepository”的 bean - Consider defining a bean of type 'com.repository.UserRepository' in your configuration 考虑在您的配置中定义一个“org.hibernate.SessionFactory”类型的 bean。 - 春天 - Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration. - Spring 考虑在配置中定义类型为&#39;com.test.project.repositories.TaskRepository&#39;的bean @Repository注解已经存在 - Consider defining a bean of type 'com.test.project.repositories.TaskRepository' in your configuration @Repository annotation is already there 考虑在您的配置中定义一个类型的 bean - Consider defining a bean of type in your configuration 例外:考虑在你的配置中定义一个类型的 bean - Exception: Consider defining a bean of type in your configuration 考虑在您的配置中定义类型为“UserConverter”的 bean - Consider defining a bean of type 'UserConverter' in your configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM