Считайте имя пользователя и пароль mongodb из settings.xml на основе выбора профиля в pom.xml.Я не понимаю, как это сделать.Может ли кто-нибудь привести пример.
Я перешел по ссылочной ссылке
https://examples.javacodegeeks.com/enterprise-java/spring/loading-environment-specific-configurations-properties-spring-using-maven-profiles-xml-settings-file-example/
pom.xml
<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">//here showing error
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Spring Maven Properties Example Code</name>
<properties>
<!-- Generic properties -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<resource.directory>src/main/resources</resource.directory>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- Test Artifacts -->
</dependencies>
<profiles>
<profile>
<id>dev</id>
<!-- Dev Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<!-- Test Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
</profile>
<profile>
<id>prod</id>
<!-- Prod Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<!-- Placeholders that are found from the files located in the configured
resource directories are replaced with the property values found from the
profile specific configuration file. -->
<resource>
<directory>${resource.directory}</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
заявка.properites
db.connectionURL=${db.connectionURL}
db.username=${db.username}
db.password=${db.password}
Я поместил файл settings.xml в директорию текущего проекта.settings.xml
<profiles>
<profile>
<id>dev</id>
<!-- Dev Env. Properties -->
<properties>
<profile.name>dev</profile.name>
<!-- Database Properties -->
<db.driverClass>com.mysql.jdbc.Driver</db.driverClass>
<db.connectionURL>jdbc:postgresql://localhost:5432/springbootdb</db.connectionURL>
<db.username>postgres</db.username>
<db.password>postgres</db.password>
</properties>
</profile>
</profiles>
MainApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Здесь я проверяю, работает ли postgres, работает она или нет, но показывает ошибку в файле pom.xml здесь
<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">
ошибка
Project build error:
Resolving expression: '${db.password}': Detected the following recursive expression cycle in 'db.password': [db.password]
Я хочу протестировать сценарии для postgres и monngodb.
Помогите мне ..