简体   繁体   English

考虑在你的配置中定义一个“com.issuemanagement.repository.IssueHistoryRepository”类型的bean

[英]Consider defining a bean of type 'com.issuemanagement.repository.IssueHistoryRepository' in your configuration

I get this error.我得到这个错误。 What can be done in this case?在这种情况下可以做什么?

APPLICATION FAILED TO START应用程序无法启动

Description: Parameter 0 of constructor in com.issuemanagement.service.impl.IssueHistoryServiceImpl required a bean of type 'com.issuemanagement.repository.IssueHistoryRepository' that could not be found.说明:com.issuemanagement.service.impl.IssueHistoryServiceImpl 中构造函数的参数 0 需要找不到类型为“com.issuemanagement.repository.IssueHistoryRepository”的 bean。

Action: Consider defining a bean of type 'com.issuemanagement.repository.IssueHistoryRepository' in your configuration.行动:考虑在你的配置中定义一个“com.issuemanagement.repository.IssueHistoryRepository”类型的bean。

IssueHistoryRepository.java IssueHistoryRepository.java

public interface IssueHistoryRepository extends JpaRepository<IssueHistory, Long>{
    
}

IssueHistoryService.java问题HistoryService.java

public interface IssueHistoryService {
    
    IssueHistory save(IssueHistory issueHistory);
    
    IssueHistory getById(Long id);
    
    Page<IssueHistory> getAllPageable(Pageable pageable);
    
    Boolean delete(IssueHistory issueHistory);
}

IssueHistoryServiceImpl.java问题HistoryServiceImpl.java

@Service
public class IssueHistoryServiceImpl implements IssueHistoryService {

    
    private final IssueHistoryRepository issueHistoryRepository;
    private final ModelMapper modelMapper;

    public IssueHistoryServiceImpl(IssueHistoryRepository issueHistoryRepository, ModelMapper modelMapper) {
        this.issueHistoryRepository = issueHistoryRepository;
        this.modelMapper = modelMapper;
    }
   
    @Override
    public IssueHistory save(IssueHistory issueHistory) {
        if(issueHistory.getDate()==null) {
            throw new IllegalArgumentException("Issue cannot be null");
        }
        issueHistory = issueHistoryRepository.save(issueHistory);
        return issueHistory;
    }

    @Override
    public IssueHistory getById(Long id) {
        
        return issueHistoryRepository.getOne(id);
    }

    @Override
    public Page<IssueHistory> getAllPageable(Pageable pageable) {
        
        return issueHistoryRepository.findAll(pageable);
    }

    @Override
    public Boolean delete(IssueHistory issueHistory) {
        
        issueHistoryRepository.delete(issueHistory);
        return Boolean.TRUE;
    }

}

IssueManagementApplication.java问题管理应用程序.java

@SpringBootApplication
@ComponentScan({"com.issuemanagement"})
@EnableAutoConfiguration
public class IssueManagementApplication {

    public static void main(String[] args) {
        SpringApplication.run(IssueManagementApplication.class, args);
    }
    
    @Bean
    public ModelMapper getModelMapper() {
        return new ModelMapper();
    }

}

You need to mark your IssueHistoryRepository.java interface with @Repository annotation.您需要使用@Repository注释标记您的IssueHistoryRepository.java接口。 This annotation will allow Spring to automatically detect your bean and to register it in ApplicationContext, from which you can autowire it.此注解将允许 Spring 自动检测您的 bean 并将其注册到 ApplicationContext 中,您可以从中自动装配它。

@SpringBootApplication encapsulates @Configuration , @EnableAutoConfiguration , and @ComponentScan annotations with their default attributes. @SpringBootApplication封装了@Configuration@EnableAutoConfiguration@ComponentScan注解及其默认属性。 The default value for @ComponentScan means that all the sub packages on the package the @ComponentScan is used are scanned. @ComponentScan的默认值表示使用@ComponentScan的package 上的所有子包都被扫描。 That is why it is usually a good practice to include the main class in the base package of the project.这就是为什么在项目的基础 package 中包含主要的 class 通常是一个很好的做法。 Having said that, please drop @ComponentScan and @EnableAutoConfiguration from your main class as follows:话虽如此,请从您的主要 class 中删除@ComponentScan@EnableAutoConfiguration ,如下所示:

@SpringBootApplication
public class IssueManagementApplication {

    public static void main(String[] args) {
        SpringApplication.run(IssueManagementApplication.class, args);
    }
    
    @Bean
    public ModelMapper getModelMapper() {
        return new ModelMapper();
    }
}

暂无
暂无

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

相关问题 考虑在您的配置中定义类型为“com.repository.UserRepository”的 bean - Consider defining a bean of type 'com.repository.UserRepository' in your configuration 考虑在您的配置中定义类型为“ com.face.ImageRepository”的bean? - Consider defining a bean of type 'com.face.ImageRepository' in your configuration? 春季启动:考虑在配置中定义类型为“ com.repository.services.interfacename”的bean - Spring boot: Consider defining a bean of type 'com.repository.services.interfacename' in your configuration 考虑在配置中定义类型为&#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 考虑在您的配置中定义类型为“com.example.conexion.repository.ClienteRepository”的 bean - Consider defining a bean of type 'com.example.conexion.repository.ClienteRepository' in your configuration 考虑在您的配置中定义一个类型的 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 考虑在你的配置中定义一个类型为 * 的 bean - Consider defining a bean of type * in your configuration 考虑在配置中定义“包”类型的bean - Consider defining a bean of type 'package' in your configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM