File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed
extensions/spring-di/deployment/src
main/java/io/quarkus/spring/di/deployment
test/java/io/quarkus/spring/di/deployment Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 3737import io .quarkus .deployment .Feature ;
3838import io .quarkus .deployment .annotations .BuildProducer ;
3939import io .quarkus .deployment .annotations .BuildStep ;
40+ import io .quarkus .deployment .annotations .BuildSteps ;
4041import io .quarkus .deployment .builditem .FeatureBuildItem ;
4142
4243/**
4344 * A simple processor that maps Spring DI annotations to CDI annotations.
4445 * Arc's handling of annotation mapping (by creating an extra abstraction layer on top of the Jandex index)
4546 * suits this sort of handling perfectly.
4647 */
48+ @ BuildSteps (onlyIf = SpringDiEnabled .class )
4749public class SpringDIProcessor {
4850
4951 private static final DotName SPRING_SCOPE_ANNOTATION = DotName .createSimple ("org.springframework.context.annotation.Scope" );
Original file line number Diff line number Diff line change 1+ package io .quarkus .spring .di .deployment ;
2+
3+ import io .quarkus .runtime .annotations .ConfigPhase ;
4+ import io .quarkus .runtime .annotations .ConfigRoot ;
5+ import io .smallrye .config .ConfigMapping ;
6+ import io .smallrye .config .WithDefault ;
7+
8+ @ ConfigMapping (prefix = "quarkus.spring-di" )
9+ @ ConfigRoot (phase = ConfigPhase .BUILD_TIME )
10+ public interface SpringDiBuildTimeConfig {
11+
12+ /**
13+ * Whether Spring DI is enabled **during the build**.
14+ * <p>
15+ * Turning this setting off will result in Quarkus completely ignoring beans annotated with Spring annotations
16+ */
17+ @ WithDefault ("true" )
18+ boolean enabled ();
19+
20+ }
Original file line number Diff line number Diff line change 1+ package io .quarkus .spring .di .deployment ;
2+
3+ import java .util .function .BooleanSupplier ;
4+
5+ public class SpringDiEnabled implements BooleanSupplier {
6+
7+ private final SpringDiBuildTimeConfig config ;
8+
9+ public SpringDiEnabled (SpringDiBuildTimeConfig config ) {
10+ this .config = config ;
11+ }
12+
13+ @ Override
14+ public boolean getAsBoolean () {
15+ return config .enabled ();
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package io .quarkus .spring .di .deployment ;
2+
3+ import jakarta .enterprise .inject .spi .DeploymentException ;
4+ import jakarta .inject .Inject ;
5+ import jakarta .inject .Singleton ;
6+
7+ import org .junit .jupiter .api .Assertions ;
8+ import org .junit .jupiter .api .Test ;
9+ import org .junit .jupiter .api .extension .RegisterExtension ;
10+ import org .springframework .stereotype .Component ;
11+
12+ import io .quarkus .test .QuarkusUnitTest ;
13+
14+ public class SpringDiDisabledTest {
15+
16+ @ RegisterExtension
17+ static final QuarkusUnitTest config = new QuarkusUnitTest ()
18+ .withApplicationRoot ((jar ) -> jar
19+ .addClasses (Foo .class , Bar .class ))
20+ .setExpectedException (DeploymentException .class )
21+ .overrideConfigKey ("quarkus.spring-di.enabled" , "false" );
22+
23+ @ Test
24+ void shouldNotBeCalled () {
25+ Assertions .fail ();
26+ }
27+
28+ @ Singleton
29+ public static class Foo {
30+
31+ @ Inject
32+ Bar bar ;
33+ }
34+
35+ @ Component
36+ public static class Bar {
37+
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments