gpt4 book ai didi

java - 使用 JOOQ 的 Spring 启动收到一条消息 "required a bean of type ' org.jooq.DSLContext' 无法找到”

转载 作者:行者123 更新时间:2023-12-02 11:33:24 28 4
gpt4 key购买 nike

我使用 spring boot 和 JOOQ 创建了一个简单的项目,添加了依赖项“spring-boot-starter-jooq”。编译时应用程序无法启动。

这是 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.bingo</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>api</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hashids</groupId>
<artifactId>hashids</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<configuration>
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://123.123.123.123:3306/dbname</url>
<user>root</user>
<password>password</password>
</jdbc>
<generator>
<database>
<name>org.jooq.util.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<inputSchema>dbname</inputSchema>
<forcedTypes>
<forcedType>
<name>CustomUUID</name>
<types>binary.*</types>
</forcedType>
<forcedType>
<name>Geometry</name>
<types>(geometry|GEOMETRY)</types>
</forcedType>
</forcedTypes>
<properties>
<property>
<key>packages</key>
<value>com.bingo.api.entity</value>
</property>
</properties>
</database>
<generate>
<pojos>true</pojos>
</generate>
</generator>
</configuration>
</plugin>
</plugins>
</build>
</project>

这是我要注入(inject) DSLContext 的地方:

@Service
public class GameDao {
private final DSLContext create;
@Autowired
public GameDao(DSLContext dslContext) {
this.create = dslContext;
}
}

错误消息:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gameDao' defined in file [/Users/yangzhiwei/Downloads/BingoApi/target/classes/com/bingo/api/dao/GameDao.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.jooq.DSLContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

/***************************

APPLICATION FAILED TO START

/***************************

Description: Parameter 0 of constructor in com.bingo.api.dao.GameDao required a bean of type 'org.jooq.DSLContext' that could not be found.
Action: Consider defining a bean of type 'org.jooq.DSLContext' in your configuration.

请问有什么帮助吗?

更新:1.我在 application.properties 文件中添加了如下属性:

spring.datasource.url==jdbc:mysql://123.123.123.123:3306/bingo
spring.datasource.user=username
spring.datasource.password=password

2.我添加了jooqConfiguration类。现在收到另一个错误消息:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jooqConfiguration': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
***************************
APPLICATION FAILED TO START
***************************

Description:

Field dataSource in com.bingo.api.config.JooqConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'

最佳答案

将 Spring Boot 2.4 或 2.5 与 jOOQ 3.15+ 结合使用的人们可能会遇到此消息的原因之一:

No qualifying bean of type 'org.jooq.DSLContext' available: expected at least 1 bean which qualifies as autowire candidate.

...是因为 jOOQ 3.15 具有新的 R2DBC 依赖项,而 Spring Boot 2.4/2.5 尚未为使用 JDBC 和 R2DBC 的第三方做好准备,另请参阅 How to fix "Consider defining a bean of type 'org.jooq.DSLContext' in your configuration." after update to jOOQ 3.15.0

大多数用户不使用 R2DBC,因此您可以排除 R2dbcAutoConfiguration(注意拼写错误。它不是 R2dbcDataAutoConfiguration):

@SpringBootApplication(exclude = { R2dbcAutoConfiguration.class })

关于java - 使用 JOOQ 的 Spring 启动收到一条消息 "required a bean of type ' org.jooq.DSLContext' 无法找到”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49115470/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com