我最近尝试将r2dbc与postgres“0.8.8.RELEASE”(pg r2dbc maven dependecy)和spring boot“2.5.2”一起使用
我在应用程序中声明了以下属性。yml:
spring: jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQL82Dialect
hibernate:
ddl-auto: create
show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect r2dbc:
url: r2dbc:postgresql://localhost:5432/postgres
username: postgres
password: postgres
pool:
enabled: true
initial-size: 00
max-size: 500
max-idle-time: 30m
validation-query: SELECT 1 sql:
init:
schema-locations: classpath:/schema.sql
mode: always
我的pplication.java:
@EnableJpaRepositories(basePackages = {"fr.mycompany.common"})
@EntityScan("fr.mycompany")
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableConfigurationProperties
public class Application {
我明确指出,“fr.company.common”在另一个子项目中,有自己的实体
我的DatabaseConfig类:
@Configuration
@EnableTransactionManagement
@EnableR2dbcRepositories(basePackages = "fr.mycompany.activite.ingester.database.repos")
@Slf4j
public class DatabaseConfig extends AbstractR2dbcConfiguration {
@Value("${spring.r2dbc.host}")
private String host;
@Value("${spring.r2dbc.username}")
private String username;
@Value("${spring.r2dbc.password}")
private String password;
@Value("${spring.r2dbc.database}")
private String database;
@Override
public ConnectionFactory connectionFactory() {
log.info("Init rd2dbc with host: {}", host);
log.info("Init rd2dbc with database: {}", database);
log.info("Init rd2dbc with username: {}", username);
log.info("Init rd2dbc with password: {}", password);
return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
.username(username)
.password(password)
.host(host)
.database(database)
.build());
}
@Bean
ReactiveTransactionManager transactionManager(ConnectionFactory connectionFactory) {
return new R2dbcTransactionManager(connectionFactory);
}
@Bean
public ConnectionFactoryInitializer initializer(ConnectionFactory connectionFactory) {
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
initializer.setConnectionFactory(connectionFactory);
CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource("schema.sql")));
populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource("data.sql")));
initializer.setDatabasePopulator(populator);
return initializer;
}
我的存储库:
public interface OrdreDeTravailPivotV2SplittedRepository extends ReactiveCrudRepository<OrdreDeTravailPivotV2SplittedEntity, OrdreDeTravailPivotV2IdEntity> {
@Query(value = "SELECT * FROM splitted.ordredetravail WHERE idot = :idOt ORDER BY datemajstatut DESC LIMIT 1", nativeQuery = true)
Optional<OrdreDeTravailPivotV2SplittedEntity> findLastByItOt(String idOt);
}
我的实体:
@Entity
@Getter
@Setter
@IdClass(OrdreDeTravailIdEntity.class)
@Table(name = "ordredetravail", schema = "splitted")
@TypeDef(
name = "jsonb",
typeClass = JsonBinaryType.class
)
public class OrdreDeTravailSplittedEntity implements ISplittedEntity {
@Id
@Column(name = "idot")
private String idOt;
@Id
@Column(name = "datemajstatut")
private Instant dateMajStatut;
最后,我的使用我的存储库的业务类:
@Slf4j
@Component
public class OrdreDeTravailConverter implements IModelConverter<OrdreDeTravailRawEntity, OrdreDeTravailSplittedEntity, OrdreDeTravailComputedEntity, OrdreDeTravailInputConversionModel> {
private final OrdreDeTravailSplittedRepository ordreDeTravailSplittedRepository;
private final OrdreDeTravailComputedRepository ordreDeTravailComputedRepository;
@Autowired
public OrdreDeTravailConverter(OrdreDeTravailSplittedRepository ordreDeTravailSplittedRepository, OrdreDeTravailComputedRepository ordreDeTravailComputedRepository) {
this.ordreDeTravailSplittedRepository = ordreDeTravailSplittedRepository;
this.ordreDeTravailComputedRepository = ordreDeTravailComputedRepository;
}
当我尝试启动应用程序时,我收到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'fr.mycompany.activite.demande.orion.ingester.database.repos.splitted.OrdreDeTravailPivotV2SplittedRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1790)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1346)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 85 more
你有什么想法吗?
向阿德里安致意
可能是因为您包含了RepositoryFactorySupport的多个实现。您需要让AnnotationRepositoryConfigurationSource#hasExplicitFilters函数返回true。在spring boot 2.4.2中,您必须使用@EnableR2dbcRepositories,并且必须有“includeFilters”或“excludeFilters”我的解决方案(kotlin):
//Custom annotations
//Used on the Repository interface
@Target(AnnotationTarget.CLASS)
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
annotation class R2dbcRepository()
//Use above the configuration class
@EnableR2dbcRepositories(includeFilters = [ComponentScan.Filter(type = FilterType.ANNOTATION, classes = [R2dbcRepository::class])])
我正在用Spring Boot实现Rest API。由于我的实体类来自另一个包的包,所以我必须使用注释来指定。此外,我使用指定定义JPA存储库的包。下面是我的项目的样子: 在我的controller类中,我有一个SeqService对象自动连线。 是一个接口,我通过它为创建了一个Bean类。在中,我自动连接了JPA存储库: 我不明白这个错误。跟排位bean有什么关系?
我正在尝试使用spring library for google cloud API: Spring-Cloud-gcp-starter-vision 但Spring应用程序上下文无法加载,出现错误: 引起原因:org.springframework.beans.factory.不满意依赖异常:错误创建在类路径资源[org/spring框架/云/gcp/自动配置/视觉/CloudVisionAut
当试图用包含所有上下文配置的抽象类运行stepdefs时,spring看到2个不同的beans parent和step def 我使用的是Spring Booking版本:2.6.4,JUnit 5和Cucumber版本7.2.3 异常堆栈跟踪: io.cucumber.core.runtime.CucumberExecutionContext.runTestCase:没有可用的“Cucumber
我尝试自动连接我的mapstruct mapper: 这是可行的: 但是为什么我不能使用: 我得到以下错误: 导致原因:org . spring framework . beans . factory . nosuchbeandidefinitionexception:没有类型为“pl . comp . window . application . mapper . windowdtomapper
问题内容: 我正在尝试构建一个全新的Spring Framework 4.0项目,而没有所有神奇的东西,而只是简单地将它踢过去。 我在这里关注该教程:http : //spring.io/guides/tutorials/data/并取得了一些成功。我只是停留在这一点上。 当我运行此单元测试时,得到以下堆栈跟踪: 根据观察和研究,似乎是在告诉我有两个EntityManager类。第一个来自hibe
我正在用Spring Boot实现Rest API。因为我的实体类来自另一个包,所以我必须用注释来指定它。另外,我使用来指定定义JPA存储库的包。下面是我的项目的样子: 在我的controller类中,我有一个SeqService对象Autowired。 是一个接口,我从它为创建了一个Bean类。在中,我对JPA存储库进行了描述: 我不明白这个错误。和排位赛bean有什么关系?