springboot 项目无法加载到 application 文件
今天遇到一个问题,项目启动可以加载到 apollo(配置中心) 中配置的配置文件,但是在自己本地resources目录下新增了一个 application.properties 文件并在里面配置了配置文件么但是不起作用的问题。
经过验证,需要在 pom.xml 文件中配置加载文件。配置如下。
<build> <finalName>simple-callback</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> <!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.6.1</version> </plugin> </plugins>
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource>
<resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>META-INF/app.properties</include> <include>**/*.properties</include> <include>**/*.yml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
上面标红的配置文件就是指定项目启动需要加载的配置文件,以上标红配置解决了 项目启动无法加载配置文件的问题