SpringBoot2 구성 JUQ MariaDB: "javax.sql 유형의 빈이 필요했습니다.DataSource'를 찾을 수 없습니다."
이 질문이 처음 있는 것은 아니고, 이 주제에 관한 기사를 많이 읽었는데, 이 문제를 해결할 수 없습니다.
필드 data source in de.foo.MariaDbConfig에는 'javax.sql' 유형의 빈이 필요합니다.DataSource'를 찾을 수 없습니다.
모든 설정은 이 기사와 같습니다.지정된 ddl sql 파일에서 코드 생성은 정상적으로 동작했습니다.데이터베이스가 MariaDB입니다.이 에러가 계속 발생하는 이유는 무엇입니까?
설정
import org.jooq.SQLDialect;
import org.jooq.impl.DataSourceConnectionProvider;
import org.jooq.impl.DefaultConfiguration;
import org.jooq.impl.DefaultDSLContext;
import org.jooq.impl.DefaultExecuteListenerProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import javax.sql.DataSource;
@Configuration
public class MariaDbConfig {
@Autowired
private DataSource dataSource;
@Bean
public DataSourceConnectionProvider connectionProvider() {
return new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource));
}
@Bean
public DefaultDSLContext dslContext(final DefaultConfiguration defaultConfiguration) {
return new DefaultDSLContext(defaultConfiguration);
}
@Bean
public DefaultConfiguration defaultConfiguration(final DataSourceConnectionProvider connectionProvider) {
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
jooqConfiguration.set(connectionProvider);
jooqConfiguration.setSQLDialect(SQLDialect.MARIADB);
jooqConfiguration.set(new DefaultExecuteListenerProvider(new ExceptionTranslator()));
return jooqConfiguration;
}
}
application.yml
spring:
application:
name: '@project.artifactId@'
datasource:
driverClassName: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/foo
username: root
password: foo123
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.foo</groupId>
<artifactId>foobar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>foobarapp</name>
<properties>
<java.version>11</java.version>
<testcontainers.version>1.15.3</testcontainers.version>
<jooq.version>3.15.2</jooq.version>
</properties>
<dependencies>
<!--WEB&IO-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- openapi generator libs -->
<!--
The open-api maven plugin generates classes with swagger-annotation.
Unfortunately, there is no feature toggle for it, therefore we have to live with generated stubs using swagger annotations
-->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.2</version>
</dependency>
<!-- Required for model classes generated by openapi-generator-maven-plugin because of bug https://github.com/OpenAPITools/openapi-generator/issues/2901
The config tag <openApiNullable> is fully supported from 5.0.0 onwards -->
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
<!-- Required by the generated API to add support for xml format-->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.12.5</version>
</dependency>
<!--DB-->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>${jooq.version}</version>
</dependency>
<!--TOOLS-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!--TEST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.27.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<!--API CODE GEN-->
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/foo.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>${project.groupId}.ui.api</apiPackage>
<modelPackage>${project.groupId}.ui.api.model</modelPackage>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>true</delegatePattern>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- Run this profile to generate DB entities from schema ddl file. -->
<profiles>
<profile>
<id>jooq</id>
<build>
<plugins>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>generate-jooq-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generator>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<pojos>false</pojos>
<daos>false</daos>
<pojosEqualsAndHashCode>true</pojosEqualsAndHashCode>
<javaTimeTypes>true</javaTimeTypes>
</generate>
<database>
<name>org.jooq.meta.extensions.ddl.DDLDatabase</name>
<inputCatalog></inputCatalog>
<inputSchema>PUBLIC</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>
<outputCatalogToDefault>true</outputCatalogToDefault>
<properties>
<property>
<key>sort</key>
<value>semantic</value>
</property>
<property>
<key>parseIgnoreComments</key>
<value>true</value>
</property>
<property>
<key>parseDialect</key>
<value>SQLSERVER</value>
</property>
<property>
<key>scripts</key>
<value>src/main/resources/foo.sql</value>
</property>
</properties>
</database>
<target>
<clean>true</clean>
<packageName>de.foo</packageName>
<directory>src/main/java</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
자체 데이터 소스도 다음과 같이 정의했지만 오류가 계속 발생합니다.
@Bean
public DataSource datasource() {
return DataSourceBuilder.create()
.driverClassName("org.mariadb.jdbc.Driver")
.url("jdbc:mariadb://localhost:3306/foo")
.username("root")
.password("foo123")
.build();
}
좋은 생각이 있으시기를 바랍니다.
그래서 Simon Martinelli는 스택오버플로우 안에서 해결책을 찾는 것을 도와주었습니다.hole config 클래스를 삭제한 후 "DSLContext that cannot found" 오류가 발생하였습니다.그러다가 이런 질문을 찾았어요
그래서 내 문제가 완전히 해결됐지이미 해결된 질문을 드려 죄송합니다만, R2dbc AutoConfiguration의 방향을 가리키는 것은 없습니다.
Simon이 이미 말했듯이 config 클래스를 삭제하고 이 질문의 답변에서 이미 지적했듯이@SpringBootApplication(exclude = { R2dbcAutoConfiguration.class })
문제를 해결했다.
언급URL : https://stackoverflow.com/questions/69162928/springboot2-configuration-jooq-mariadb-required-a-bean-of-type-javax-sql-data
'sourcecode' 카테고리의 다른 글
String.replace모든 단일 백슬래시를 이중 백슬래시로 바꿉니다. (0) | 2022.09.22 |
---|---|
여러 파일에 걸쳐 구성된 Python 클래스를 사용할 수 있습니까? (0) | 2022.09.22 |
변수 앞에 더하기 기호가 있는 목적은 무엇입니까? (0) | 2022.09.22 |
MySQL에서 날짜 범위의 중복 확인 (0) | 2022.09.22 |
JavaScript를 사용하여 파일 확장자를 얻는 방법은 무엇입니까? (0) | 2022.09.22 |