定义豆子的春季启动
我有一个有趣的错误,我说这很有趣,因为我的项目正常工作,而且崩溃了。
我相信我已经实施了我应该实施的一切来实现多数据源。
在上下文初始化中遇到的异常 - 取消刷新尝试:org.springframework.beans.factory.unsatisfieddepperencyenception:错误创建用名称'quoteController'创建bean [c:\ users \ s4 \ s4 \ desktop \ s4 \ desktop \ s4projects \ s4projects \ s4projects \ s4projects \ sove intrananet \ source intrananet \ source intrananet \ sim \ back-end \ target \ class \ com \ api \ controllers \ quotecontroller.class]:通过构造函数参数0表示的不满意的依赖性; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quoteServiceImpl' defined in file [C:\Users\S4\Desktop\S4Projects\wirk-devserv-intranet\source\back-end\target\类\ com \ api \ services \ servission \ quoteserviceimpl.class]:通过构造函数参数1表示不满意的依赖性;嵌套的异常是org.springframework.beans.factory.nosuchbeandefinitionException:没有合格的bean of类型'com.api.repository.customer.customerreposore.customerrepository'可用:预期的至少1 bean,符合自动候选人的资格。依赖关系注释:{}
描述:
com.api.services.implementation.quoteserviceimpl中的构造函数的参数1所需的bean com.api.repository.customer.customerreposority'''
操作:
考虑在您的配置中定义'com.api.repository.customer.customerrepository'类型的bean。
@Autowired
private final CustomerRepository customerRepository;
@Autowired
private final QuoteRepository quoteRepository;
@Component
public interface CustomerRepository extends JpaRepository<Customer,
Integer> {
}
配置文件
@EnableJpaRepositories(
basePackageClasses = {
QuoteRepository.class,
CustomerConfig.class
},
entityManagerFactoryRef = "quoteEntityManager",
transactionManagerRef = "quoteTransactionManager")
public class QuoteConfig {
@Bean(name = "quoteEntityManager")
@Primary
public LocalContainerEntityManagerFactoryBean quoteEntityManager(EntityManagerFactoryBuilder builder, @Qualifier("quoteDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages(Quote.class)
.persistenceUnit("S4DevservIntranet")
.build();
}
@Primary
@Bean("quoteDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource quoteDataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean("quoteTransactionManager")
public PlatformTransactionManager quoteTransactionManager(@Qualifier("quoteEntityManager") LocalContainerEntityManagerFactoryBean quoteEntityManager) {
return new JpaTransactionManager(Objects.requireNonNull(quoteEntityManager.getObject()));
}
}
I have this funny error, I say it is funny because my project was working and it just crashed.
I believe I have implemented everything I was supposed to implement to achieve the multi data source.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quoteController' defined in file [C:\Users\S4\Desktop\S4Projects\wirk-devserv-intranet\source\back-end\target\classes\com\api\controllers\QuoteController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quoteServiceImpl' defined in file [C:\Users\S4\Desktop\S4Projects\wirk-devserv-intranet\source\back-end\target\classes\com\api\services\implementation\QuoteServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.api.repository.customer.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Description:
Parameter 1 of constructor in com.api.services.implementation.QuoteServiceImpl required a bean of type 'com.api.repository.customer.CustomerRepository' that could not be found.
Action:
Consider defining a bean of type 'com.api.repository.customer.CustomerRepository' in your configuration.
@Autowired
private final CustomerRepository customerRepository;
@Autowired
private final QuoteRepository quoteRepository;
@Component
public interface CustomerRepository extends JpaRepository<Customer,
Integer> {
}
Config File
@EnableJpaRepositories(
basePackageClasses = {
QuoteRepository.class,
CustomerConfig.class
},
entityManagerFactoryRef = "quoteEntityManager",
transactionManagerRef = "quoteTransactionManager")
public class QuoteConfig {
@Bean(name = "quoteEntityManager")
@Primary
public LocalContainerEntityManagerFactoryBean quoteEntityManager(EntityManagerFactoryBuilder builder, @Qualifier("quoteDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages(Quote.class)
.persistenceUnit("S4DevservIntranet")
.build();
}
@Primary
@Bean("quoteDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource quoteDataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean("quoteTransactionManager")
public PlatformTransactionManager quoteTransactionManager(@Qualifier("quoteEntityManager") LocalContainerEntityManagerFactoryBean quoteEntityManager) {
return new JpaTransactionManager(Objects.requireNonNull(quoteEntityManager.getObject()));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
:
It must be:
错误消息告诉它一切,似乎您没有为CustomerRepository创建BEAN,因此请使用@repository或@component注释类。
Error Message tells it everything, seems you haven't created bean for CustomerRepository, so annotate the class with @Repository or @Component.