1、首先考虑你的pom.xml的依赖有没有放好:
该配置项要想生效其实是依赖于项目中内嵌的tomcat容器:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

2、如果你发现target\classes文件下,没有生成配置文件。

Build Path -> Configure Build Path... -> java Build Path -> Source

src/main/resources中,将Excluded:** 改为 None

或者:

项目右键 ---> Properties ---> Java Build Path ---> Source ---> Excluded 设置为None。

3、会不会是你的pom.xml中多写了什么,有些人多写了,导致改不了:

 <packaging>pom</packaging>

4、指定启动端口号8022,覆盖配置文件。

@SpringBootApplication
public class FadadaApplication {

	public static void main(String[] args) {
		SpringApplication.run(FadadaApplication.class, args);
	}
	
	@Bean
	public TomcatServletWebServerFactory servletContainer(){
	   return new TomcatServletWebServerFactory(8022) ;
	}
}

5、修改端口的四种方式你对了吗

方式一: 配置文件 application.properties
server.port=7788
方式二: java启动命令
// 以应用参数的方式
java -jar --server.port=7788
// 或以 jdk 参数的方式
java -dserver.port=7788 -jar
方式三: 环境变量 server_port
linux环境下使用:
server_port=7788 java -jar
windows环境下使用:
set server_port=7788
java -jar
方式四: 环境变量 spring_application_json
linux:
spring_application_json='{"server.port":7788}' java -jar
// 或者是
java -dspring.application.json='{"server.port":7788}' -jar
// 或者是
java -jar --spring.application.json='{"server.port":7788}'
参数优先级
动命令应用参数 > 启动命令 jdk 参数 > 环境变量
如果我们同时给定这些参数, 如下:
server_port=3344 java -dserver.port=5566 -jar --server.port=7788
生效的是 --server.port=7788 这个参数.

在这里插入图片描述
6、再来想想有没有可能是加载资源的时候不加载resources文件,单独给他来个配置?在pom.xml中加入这个,位置要放对啊同志们。

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>context.xml</include>
            </includes>
        </resource>
 
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>context.xml</exclude>
            </excludes>
        </resource>
    </resources>
</build>

7、听说你还不能解决?
只剩一个方法了:(如果没有显示,改掉文件格式吧,用yml格式吧)

你点击server.然后选择,一定一定要点击一下这个,让它自己选择,然后在他们后面写8081

在这里插入图片描述
在这里插入图片描述


//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//            佛祖保佑       永不宕机     永无BUG                    //

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐