0

这是我的项目在 pom.xml 中的构建配置,当我打包项目时,属性文件已经随所选配置文件属性发生了变化,但是当我使用 maven-boot-plugin:run in 运行项目时Intellij IDEA,属性文件发生了变化旧样式和数据库连接引发异常。例如,正常的 application.properties 具有以下键:

spring.datasource.url=${datasourceUrl}

打包项目后是:

spring.datasource.url=url1

但是在运行 spring boot 插件后,属性文件更改为第一种样式。

<profiles>
    <profile>
        <id>Live</id>
        <properties>
            <datasourceUrl>url1</datasourceUrl>
        </properties>
    </profile>

    <profile>
        <id>Test</id>
        <properties>
            <datasourceUrl>url2</datasourceUrl>
        </properties>
    </profile>
</profiles>


<build>
    <defaultGoal>install</defaultGoal>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.*</include>

            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <id>run</id>
                    <phase>package</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

            <executions>
                <execution>
                    <id>repack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                mywar 
                                <type>war</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>${project.build.directory}/classes/static/</outputDirectory>
                                <includes>**/*</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
4

0 回答 0