Skip to content

Commit c8e0791

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-28379
2 parents bc2bf84 + 5fe75f3 commit c8e0791

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.jooq;
18+
19+
import org.jooq.DSLContext;
20+
21+
import org.springframework.beans.BeansException;
22+
import org.springframework.beans.factory.BeanFactory;
23+
import org.springframework.beans.factory.BeanFactoryAware;
24+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
25+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
26+
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
27+
import org.springframework.boot.diagnostics.FailureAnalysis;
28+
import org.springframework.core.Ordered;
29+
30+
class NoDslContextBeanFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchBeanDefinitionException>
31+
implements Ordered, BeanFactoryAware {
32+
33+
private BeanFactory beanFactory;
34+
35+
@Override
36+
protected FailureAnalysis analyze(Throwable rootFailure, NoSuchBeanDefinitionException cause) {
37+
if (DSLContext.class.equals(cause.getBeanType()) && hasR2dbcAutoConfiguration()) {
38+
return new FailureAnalysis(
39+
"jOOQ has not been auto-configured as R2DBC has been auto-configured in favor of JDBC and jOOQ "
40+
+ "auto-configuration does not yet support R2DBC. ",
41+
"To use jOOQ with JDBC, exclude R2dbcAutoConfiguration. To use jOOQ with R2DBC, define your own "
42+
+ "jOOQ configuration.",
43+
cause);
44+
}
45+
return null;
46+
}
47+
48+
private boolean hasR2dbcAutoConfiguration() {
49+
try {
50+
this.beanFactory.getBean(R2dbcAutoConfiguration.class);
51+
return true;
52+
}
53+
catch (Exception ex) {
54+
return false;
55+
}
56+
}
57+
58+
@Override
59+
public int getOrder() {
60+
return 0;
61+
}
62+
63+
@Override
64+
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
65+
this.beanFactory = beanFactory;
66+
67+
}
68+
69+
}

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinition
162162
org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingFailureAnalyzer,\
163163
org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
164164
org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
165+
org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer,\
165166
org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBeanCreationFailureAnalyzer,\
166167
org.springframework.boot.autoconfigure.session.NonUniqueSessionRepositoryFailureAnalyzer
167168

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.jooq;
18+
19+
import org.jooq.DSLContext;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
23+
import org.springframework.boot.autoconfigure.AutoConfigurations;
24+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
25+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* Tests for {@link NoDslContextBeanFailureAnalyzer}.
31+
*
32+
* @author Andy Wilkinson
33+
*/
34+
class NoDslContextBeanFailureAnalyzerTests {
35+
36+
private final NoDslContextBeanFailureAnalyzer failureAnalyzer = new NoDslContextBeanFailureAnalyzer();
37+
38+
@Test
39+
void noAnalysisWithoutR2dbcAutoConfiguration() {
40+
new ApplicationContextRunner().run((context) -> {
41+
this.failureAnalyzer.setBeanFactory(context.getBeanFactory());
42+
assertThat(this.failureAnalyzer.analyze(new NoSuchBeanDefinitionException(DSLContext.class))).isNull();
43+
});
44+
}
45+
46+
@Test
47+
void analysisWithR2dbcAutoConfiguration() {
48+
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class))
49+
.run((context) -> {
50+
this.failureAnalyzer.setBeanFactory(context.getBeanFactory());
51+
assertThat(this.failureAnalyzer.analyze(new NoSuchBeanDefinitionException(DSLContext.class)))
52+
.isNotNull();
53+
});
54+
}
55+
56+
}

0 commit comments

Comments
 (0)