mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Spring Boot properties extension
This commit is contained in:
@@ -501,6 +501,11 @@
|
||||
<artifactId>quarkus-spring-data-deployment</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-spring-boot-properties-deployment</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jgit-deployment</artifactId>
|
||||
|
||||
@@ -167,6 +167,7 @@
|
||||
<spring.version>5.1.8.RELEASE</spring.version>
|
||||
<spring-data.version>2.1.9.RELEASE</spring-data.version>
|
||||
<spring-security.version>5.2.0.RELEASE</spring-security.version>
|
||||
<spring-boot.version>2.1.10.RELEASE</spring-boot.version>
|
||||
<mvel2.version>2.4.4.Final</mvel2.version>
|
||||
<mockito.version>3.0.0</mockito.version>
|
||||
<jna.version>5.3.1</jna.version>
|
||||
@@ -640,6 +641,11 @@
|
||||
<artifactId>quarkus-spring-data-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-spring-boot-properties</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-swagger-ui</artifactId>
|
||||
@@ -2556,6 +2562,23 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Keycloak -->
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
|
||||
@@ -363,6 +363,7 @@ stages:
|
||||
- spring-di
|
||||
- spring-web
|
||||
- spring-data-jpa
|
||||
- spring-boot-properties
|
||||
name: spring
|
||||
|
||||
- template: native-build-steps.yaml
|
||||
|
||||
@@ -79,6 +79,7 @@ public final class FeatureBuildItem extends MultiBuildItem {
|
||||
public static final String SPRING_WEB = "spring-web";
|
||||
public static final String SPRING_DATA_JPA = "spring-data-jpa";
|
||||
public static final String SPRING_SECURITY = "spring-security";
|
||||
public static final String SPRING_BOOT_PROPERTIES = "spring-boot-properties";
|
||||
public static final String SWAGGER_UI = "swagger-ui";
|
||||
public static final String TIKA = "tika";
|
||||
public static final String UNDERTOW_WEBSOCKETS = "undertow-websockets";
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
package io.quarkus.arc.deployment.configproperties;
|
||||
|
||||
import static io.quarkus.runtime.util.StringUtil.camelHumpsIterator;
|
||||
import static io.quarkus.runtime.util.StringUtil.join;
|
||||
import static io.quarkus.runtime.util.StringUtil.lowerCase;
|
||||
import static io.quarkus.runtime.util.StringUtil.withoutSuffix;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
||||
import io.quarkus.arc.config.ConfigProperties;
|
||||
import io.quarkus.arc.deployment.ConfigPropertyBuildItem;
|
||||
import io.quarkus.arc.deployment.GeneratedBeanBuildItem;
|
||||
import io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor;
|
||||
@@ -35,17 +27,24 @@ import io.quarkus.gizmo.ClassOutput;
|
||||
|
||||
public class ConfigPropertiesBuildStep {
|
||||
|
||||
@BuildStep
|
||||
void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex,
|
||||
BuildProducer<ConfigPropertiesMetadataBuildItem> configPropertiesMetadataProducer) {
|
||||
for (AnnotationInstance annotation : combinedIndex.getIndex().getAnnotations(DotNames.CONFIG_PROPERTIES)) {
|
||||
configPropertiesMetadataProducer.produce(new ConfigPropertiesMetadataBuildItem(annotation));
|
||||
}
|
||||
}
|
||||
|
||||
@BuildStep
|
||||
void setup(CombinedIndexBuildItem combinedIndex,
|
||||
ApplicationIndexBuildItem applicationIndex,
|
||||
List<ConfigPropertiesMetadataBuildItem> configPropertiesMetadataList,
|
||||
BuildProducer<GeneratedClassBuildItem> generatedClasses,
|
||||
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
|
||||
BuildProducer<RunTimeConfigurationDefaultBuildItem> defaultConfigValues,
|
||||
BuildProducer<ConfigPropertyBuildItem> configProperties,
|
||||
DeploymentClassLoaderBuildItem deploymentClassLoader) {
|
||||
IndexView index = combinedIndex.getIndex();
|
||||
Collection<AnnotationInstance> instances = index.getAnnotations(DotNames.CONFIG_PROPERTIES);
|
||||
if (instances.isEmpty()) {
|
||||
if (configPropertiesMetadataList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,11 +61,10 @@ public class ConfigPropertiesBuildStep {
|
||||
.build();
|
||||
producerClassCreator.addAnnotation(Singleton.class);
|
||||
|
||||
Set<DotName> configClassesThatNeedValidation = new HashSet<>(instances.size());
|
||||
for (AnnotationInstance configPropertiesInstance : instances) {
|
||||
ClassInfo classInfo = configPropertiesInstance.target().asClass();
|
||||
Set<DotName> configClassesThatNeedValidation = new HashSet<>(configPropertiesMetadataList.size());
|
||||
for (ConfigPropertiesMetadataBuildItem configPropertiesMetadata : configPropertiesMetadataList) {
|
||||
ClassInfo classInfo = configPropertiesMetadata.getClassInfo();
|
||||
|
||||
String prefixStr = determinePrefix(configPropertiesInstance);
|
||||
if (Modifier.isInterface(classInfo.flags())) {
|
||||
/*
|
||||
* In this case we need to generate an implementation of the interface that for each interface method
|
||||
@@ -75,7 +73,7 @@ public class ConfigPropertiesBuildStep {
|
||||
*/
|
||||
|
||||
String generatedClassName = InterfaceConfigPropertiesUtil.generateImplementationForInterfaceConfigProperties(
|
||||
classInfo, nonBeansClassOutput, index, prefixStr,
|
||||
classInfo, nonBeansClassOutput, combinedIndex.getIndex(), configPropertiesMetadata.getPrefix(),
|
||||
defaultConfigValues, configProperties);
|
||||
InterfaceConfigPropertiesUtil.addProducerMethodForInterfaceConfigProperties(producerClassCreator,
|
||||
classInfo.name(), generatedClassName);
|
||||
@@ -86,8 +84,8 @@ public class ConfigPropertiesBuildStep {
|
||||
* and call setters for value obtained from MP Config
|
||||
*/
|
||||
boolean needsValidation = ClassConfigPropertiesUtil.addProducerMethodForClassConfigProperties(
|
||||
deploymentClassLoader.getClassLoader(), classInfo, producerClassCreator, prefixStr,
|
||||
applicationIndex.getIndex(), configProperties);
|
||||
deploymentClassLoader.getClassLoader(), classInfo, producerClassCreator,
|
||||
configPropertiesMetadata.getPrefix(), applicationIndex.getIndex(), configProperties);
|
||||
if (needsValidation) {
|
||||
configClassesThatNeedValidation.add(classInfo.name());
|
||||
}
|
||||
@@ -101,35 +99,4 @@ public class ConfigPropertiesBuildStep {
|
||||
configClassesThatNeedValidation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the annotation value
|
||||
*/
|
||||
private String determinePrefix(AnnotationInstance configPropertiesInstance) {
|
||||
String fromAnnotation = getPrefixFromAnnotation(configPropertiesInstance);
|
||||
if (fromAnnotation != null) {
|
||||
return fromAnnotation;
|
||||
}
|
||||
return getPrefixFromClassName(configPropertiesInstance.target().asClass().name());
|
||||
}
|
||||
|
||||
private String getPrefixFromAnnotation(AnnotationInstance configPropertiesInstance) {
|
||||
AnnotationValue annotationValue = configPropertiesInstance.value("prefix");
|
||||
if (annotationValue == null) {
|
||||
return null;
|
||||
}
|
||||
String value = annotationValue.asString();
|
||||
if (ConfigProperties.UNSET_PREFIX.equals(value) || value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String getPrefixFromClassName(DotName className) {
|
||||
String simpleName = className.isInner() ? className.local() : className.withoutPackagePrefix();
|
||||
return join("-",
|
||||
withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration",
|
||||
"properties", "props"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.quarkus.arc.deployment.configproperties;
|
||||
|
||||
import static io.quarkus.runtime.util.StringUtil.camelHumpsIterator;
|
||||
import static io.quarkus.runtime.util.StringUtil.join;
|
||||
import static io.quarkus.runtime.util.StringUtil.lowerCase;
|
||||
import static io.quarkus.runtime.util.StringUtil.withoutSuffix;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
import io.quarkus.arc.config.ConfigProperties;
|
||||
import io.quarkus.builder.item.MultiBuildItem;
|
||||
|
||||
public final class ConfigPropertiesMetadataBuildItem extends MultiBuildItem {
|
||||
|
||||
private static final DotName CONFIG_PROPERTIES_ANNOTATION = DotName.createSimple(ConfigProperties.class.getName());
|
||||
|
||||
private final ClassInfo classInfo;
|
||||
|
||||
private final String prefix;
|
||||
|
||||
public ConfigPropertiesMetadataBuildItem(AnnotationInstance annotation) {
|
||||
if (!CONFIG_PROPERTIES_ANNOTATION.equals(annotation.name())) {
|
||||
throw new IllegalArgumentException(annotation + " is not an instance of " + ConfigProperties.class.getSimpleName());
|
||||
}
|
||||
|
||||
this.classInfo = annotation.target().asClass();
|
||||
this.prefix = extractPrefix(annotation);
|
||||
}
|
||||
|
||||
public ConfigPropertiesMetadataBuildItem(ClassInfo classInfo, String prefix) {
|
||||
this.classInfo = classInfo;
|
||||
this.prefix = sanitisePrefix(prefix);
|
||||
}
|
||||
|
||||
public ClassInfo getClassInfo() {
|
||||
return classInfo;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
private String extractPrefix(AnnotationInstance annotationInstance) {
|
||||
AnnotationValue value = annotationInstance.value("prefix");
|
||||
return sanitisePrefix(value == null ? null : value.asString());
|
||||
}
|
||||
|
||||
private String sanitisePrefix(String prefix) {
|
||||
if (isPrefixUnset(prefix)) {
|
||||
return getPrefixFromClassName(classInfo.name());
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
private boolean isPrefixUnset(String prefix) {
|
||||
return prefix == null || "".equals(prefix.trim()) || ConfigProperties.UNSET_PREFIX.equals(prefix.trim());
|
||||
}
|
||||
|
||||
private String getPrefixFromClassName(DotName className) {
|
||||
String simpleName = className.isInner() ? className.local() : className.withoutPackagePrefix();
|
||||
return join("-",
|
||||
withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration",
|
||||
"properties", "props"));
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@
|
||||
<module>spring-web</module>
|
||||
<module>spring-data-jpa</module>
|
||||
<module>spring-security</module>
|
||||
<module>spring-boot-properties</module>
|
||||
|
||||
<!-- Security -->
|
||||
<module>security</module>
|
||||
|
||||
42
extensions/spring-boot-properties/deployment/pom.xml
Normal file
42
extensions/spring-boot-properties/deployment/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>quarkus-spring-boot-properties-parent</artifactId>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<version>999-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>quarkus-spring-boot-properties-deployment</artifactId>
|
||||
<name>Quarkus - Spring Boot - Properties - Deployment</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-spring-boot-properties</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc-deployment</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-extension-processor</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.quarkus.spring.boot.properties.deployment;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.jandex.IndexView;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import io.quarkus.arc.deployment.configproperties.ConfigPropertiesMetadataBuildItem;
|
||||
import io.quarkus.deployment.annotations.BuildProducer;
|
||||
import io.quarkus.deployment.annotations.BuildStep;
|
||||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
|
||||
import io.quarkus.deployment.builditem.FeatureBuildItem;
|
||||
|
||||
public class ConfigurationPropertiesProcessor {
|
||||
|
||||
private static final DotName CONFIGURATION_PROPERTIES_ANNOTATION = DotName
|
||||
.createSimple(ConfigurationProperties.class.getName());
|
||||
|
||||
@BuildStep
|
||||
public FeatureBuildItem registerFeature() {
|
||||
return new FeatureBuildItem(FeatureBuildItem.SPRING_BOOT_PROPERTIES);
|
||||
}
|
||||
|
||||
@BuildStep
|
||||
public void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex,
|
||||
BuildProducer<ConfigPropertiesMetadataBuildItem> configPropertiesMetadataProducer) {
|
||||
combinedIndex.getIndex()
|
||||
.getAnnotations(CONFIGURATION_PROPERTIES_ANNOTATION)
|
||||
.stream()
|
||||
.map(annotation -> createConfigPropertiesMetadata(annotation, combinedIndex.getIndex()))
|
||||
.forEach(configPropertiesMetadataProducer::produce);
|
||||
}
|
||||
|
||||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadata(AnnotationInstance annotation, IndexView index) {
|
||||
switch (annotation.target().kind()) {
|
||||
case CLASS:
|
||||
return createConfigPropertiesMetadataFromClass(annotation);
|
||||
case METHOD:
|
||||
return createConfigPropertiesMetadataFromMethod(annotation, index);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported annotation target kind " + annotation.target().kind().name());
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromClass(AnnotationInstance annotation) {
|
||||
return new ConfigPropertiesMetadataBuildItem(annotation.target().asClass(), getPrefix(annotation));
|
||||
}
|
||||
|
||||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromMethod(AnnotationInstance annotation,
|
||||
IndexView index) {
|
||||
return new ConfigPropertiesMetadataBuildItem(index.getClassByName(annotation.target().asMethod().returnType().name()),
|
||||
getPrefix(annotation));
|
||||
}
|
||||
|
||||
private String getPrefix(AnnotationInstance annotation) {
|
||||
if (annotation.value() != null) {
|
||||
return annotation.value().asString();
|
||||
} else if (annotation.value("prefix") != null) {
|
||||
return annotation.value("prefix").asString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
21
extensions/spring-boot-properties/pom.xml
Normal file
21
extensions/spring-boot-properties/pom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>quarkus-build-parent</artifactId>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<version>999-SNAPSHOT</version>
|
||||
<relativePath>../../build-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>quarkus-spring-boot-properties-parent</artifactId>
|
||||
<name>Quarkus - Spring Boot - Properties</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>deployment</module>
|
||||
<module>runtime</module>
|
||||
</modules>
|
||||
</project>
|
||||
31
extensions/spring-boot-properties/runtime/pom.xml
Normal file
31
extensions/spring-boot-properties/runtime/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>quarkus-spring-boot-properties-parent</artifactId>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<version>999-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>quarkus-spring-boot-properties</artifactId>
|
||||
<name>Quarkus - Spring Boot - Properties - Runtime</name>
|
||||
<description>Use Spring Boot properties annotations to configure your application</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
name: "Quarkus Extension for Spring Boot properties"
|
||||
metadata:
|
||||
keywords:
|
||||
- "spring-boot"
|
||||
- "properties"
|
||||
categories:
|
||||
- "compatibility"
|
||||
status: "preview"
|
||||
@@ -47,6 +47,7 @@
|
||||
<module>spring-di</module>
|
||||
<module>spring-web</module>
|
||||
<module>spring-data-jpa</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>infinispan-cache-jpa</module>
|
||||
<module>elytron-security</module>
|
||||
<module>elytron-security-oauth2</module>
|
||||
|
||||
113
integration-tests/spring-boot-properties/pom.xml
Normal file
113
integration-tests/spring-boot-properties/pom.xml
Normal file
@@ -0,0 +1,113 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>quarkus-integration-tests-parent</artifactId>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<version>999-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>quarkus-integration-test-spring-boot-properties</artifactId>
|
||||
<name>Quarkus - Integration Tests - Spring Boot properties</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-resteasy</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-spring-boot-properties</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native-image</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>native-image</id>
|
||||
<goals>
|
||||
<goal>native-image</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<cleanupServer>true</cleanupServer>
|
||||
<enableHttpUrlHandler>true</enableHttpUrlHandler>
|
||||
<graalvmHome>${graalvmHome}</graalvmHome>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
public final class AnotherClass {
|
||||
|
||||
private boolean value;
|
||||
|
||||
public boolean isValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
public final class BeanProperties {
|
||||
|
||||
private int value;
|
||||
|
||||
private InnerClass innerClass;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public InnerClass getInnerClass() {
|
||||
return innerClass;
|
||||
}
|
||||
|
||||
public void setInnerClass(InnerClass innerClass) {
|
||||
this.innerClass = innerClass;
|
||||
}
|
||||
|
||||
public static class InnerClass {
|
||||
|
||||
private String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/bean")
|
||||
public class BeanPropertiesResource {
|
||||
|
||||
@Inject
|
||||
BeanProperties properties;
|
||||
|
||||
@Path("/value")
|
||||
@GET
|
||||
public int getValue() {
|
||||
return properties.getValue();
|
||||
}
|
||||
|
||||
@Path("/innerClass/value")
|
||||
@GET
|
||||
public String getInnerClassValue() {
|
||||
return properties.getInnerClass().getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("cl")
|
||||
public final class ClassProperties {
|
||||
|
||||
private String value;
|
||||
|
||||
private AnotherClass anotherClass;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public AnotherClass getAnotherClass() {
|
||||
return anotherClass;
|
||||
}
|
||||
|
||||
public void setAnotherClass(AnotherClass anotherClass) {
|
||||
this.anotherClass = anotherClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/class")
|
||||
public class ClassPropertiesResource {
|
||||
|
||||
@Inject
|
||||
ClassProperties properties;
|
||||
|
||||
@Path("/value")
|
||||
@GET
|
||||
public String getValue() {
|
||||
return properties.getValue();
|
||||
}
|
||||
|
||||
@Path("/anotherClass/value")
|
||||
@GET
|
||||
public boolean isAnotherClassValue() {
|
||||
return properties.getAnotherClass().isValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties
|
||||
public class DefaultProperties {
|
||||
|
||||
private String value = "default-value";
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/default")
|
||||
public class DefaultPropertiesResource {
|
||||
|
||||
@Inject
|
||||
DefaultProperties properties;
|
||||
|
||||
@Path("/value")
|
||||
@GET
|
||||
public String getDefaultValue() {
|
||||
return properties.getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties
|
||||
public interface InterfaceProperties {
|
||||
|
||||
String getValue();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/interface")
|
||||
public class InterfacePropertiesResource {
|
||||
|
||||
@Inject
|
||||
InterfaceProperties properties;
|
||||
|
||||
@Path("/value")
|
||||
@GET
|
||||
public String getValue() {
|
||||
return properties.getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
public class SampleApplication {
|
||||
|
||||
@ConfigurationProperties
|
||||
public BeanProperties beanProperties() {
|
||||
return new BeanProperties();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
cl.value=class-value
|
||||
cl.anotherClass.value=true
|
||||
bean.value=1
|
||||
bean.innerClass.value=inner-class-value
|
||||
interface.value=interface-value
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import io.quarkus.test.junit.NativeImageTest;
|
||||
|
||||
@NativeImageTest
|
||||
class BeanPropertiesIT extends BeanPropertiesTest {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import static io.restassured.RestAssured.when;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
|
||||
@QuarkusTest
|
||||
class BeanPropertiesTest {
|
||||
|
||||
@Test
|
||||
void shouldHaveValue() {
|
||||
when().get("/bean/value")
|
||||
.then()
|
||||
.body(is(equalTo("1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveInnerClassValue() {
|
||||
when().get("/bean/innerClass/value")
|
||||
.then()
|
||||
.body(is(equalTo("inner-class-value")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import io.quarkus.test.junit.NativeImageTest;
|
||||
|
||||
@NativeImageTest
|
||||
class ClassPropertiesIT extends ClassPropertiesTest {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import static io.restassured.RestAssured.when;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
|
||||
@QuarkusTest
|
||||
class ClassPropertiesTest {
|
||||
|
||||
@Test
|
||||
void shouldHaveValue() {
|
||||
when().get("/class/value")
|
||||
.then()
|
||||
.body(is(equalTo("class-value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveAnotherClassValue() {
|
||||
when().get("/class/anotherClass/value")
|
||||
.then()
|
||||
.body(is(equalTo("true")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import io.quarkus.test.junit.NativeImageTest;
|
||||
|
||||
@NativeImageTest
|
||||
class DefaultPropertiesIT extends DefaultPropertiesTest {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import static io.restassured.RestAssured.when;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
|
||||
@QuarkusTest
|
||||
class DefaultPropertiesTest {
|
||||
|
||||
@Test
|
||||
void shouldGetDefaultValue() {
|
||||
when().get("/default/value")
|
||||
.then()
|
||||
.body(is(equalTo("default-value")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import io.quarkus.test.junit.NativeImageTest;
|
||||
|
||||
@NativeImageTest
|
||||
class InterfacePropertiesIT extends InterfacePropertiesTest {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.quarkus.it.spring.boot;
|
||||
|
||||
import static io.restassured.RestAssured.when;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
|
||||
@QuarkusTest
|
||||
class InterfacePropertiesTest {
|
||||
|
||||
@Test
|
||||
void shouldHaveInt() {
|
||||
when().get("/interface/value")
|
||||
.then()
|
||||
.body(is(equalTo("interface-value")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user