springboot (maven) project packaging problem

Problem description:

Today, I encountered a problem during project testing. When starting the project, after modifying the external configuration file, the startup fails or the log file path is incorrect.
Our project is a springboot project, which runs as a jar package, and some configuration files are placed outside the jar package.

The reason for the above problem is that there are configuration files with the same name in the running jar package and outside the jar package.

According to the maven configuration in the current project, a configuration file will be included in the jar package during packaging, and when there are configuration files with the same name in the jar package and outside the jar package, certain conflicts will occur. (On the Internet, there is a priority choice, and only one will be selected, but the actual test found that both will take effect)

Solution:

Our previous practice was to create the jar package first, and then use the compression software to delete the configuration files in the jar to ensure that there are only configuration files outside the jar package.
However, when testing and subsequent production processes are packaged and deployed, they are not willing to do this. Therefore, it is necessary to simplify the process of packaging and deleting the configuration files in the jar.
The specific method is to add the configuration of resources in the pom.xml file of the project:

<build>
    <plugins>
       <plugin>
           <!--The original configuration here, omitted -->
       </plugin>
    </plugins>
                <!--The following is the new configuration-->
   <resources>
      <resource>
          <directory>src/main/resources
           <excludes>
               <exclude>*.properties
               <exclude>logback.xml
               <exclude>*.dat
           </excludes>
      </resource>
   </resources>
 </build>
 

With this configuration, the files ending in properties, dat, and logback.xml files will be excluded when packaging, which can solve the above problems.
It should be noted that these configuration files are no longer included in the jar package at this time, and the jar package and the relevant configuration files on svn need to be tested and produced together during deployment.

New problems and solutions:

The above operations solve the deployment process problem, but bring new development process problems.
Although packaging can successfully exclude resource files and simplify the operation steps of packaging and deployment, resource files cannot be found when running in eclipse, resulting in startup failure.
The solution is to annotate the configuration of the above resources during our development process, and uncomment it before packaging and external operation.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325371481&siteId=291194637