SpringBoot学习笔记(八):SpringBoot启动端口+访问路、SpringBoot配置文件yml、SpringBoot多环境区分、SpringBoot打包发布
2024-10-13 17:25:32
SpringBoot启动端口+访问路径
配置文件:
server.port=9090
server.context-path=/springboot
现在只能用http://127.0.0.1:9090/springboot才能访问到项目
SpringBoot配置文件yml
下面讲一下SpringBoot中另外一种格式的配置文件,名为application.yml的配置文件,这种配置文件更方便我们使用,有提示功能,而且SpringBoot也是默认去读取这个格式的配置文件,我们这里改变一下配置文件的风格。
原来的配置文件:
server.port=9090
server.context-path=/springboot
spring.datasource.url=jdbc:mysql://localhost:3306/springboot_mjxy
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#mybatis.mapper-locations=classpath:mapper/*.xml
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
name=majiaxueyuan
下面我们把它改造成application.yml的风格,非常有层次感
server:
port: 80
context-path: /springboot
spring:
datasource:
username: root
password: admin
url: jdbc:mysql://localhost:3306/springboot_mjxy?characterEncoding=utf8
thymeleaf:
cache: false
mode: LEGACYHTML5
prefix: classpath:/templates/
suffix: .html
如果没有高亮,请在eclipse中安装SpringToolsSuits。然后重启eclipse,选择打开方式就可以高亮了。
SpringBoot多环境区分
我们可以创建多个配置文件,只需要在源配置文件上面增加下面的一个配置
spring:
profiles:
active: lx
这样系统就会优先去扫描配置文件是application-lx.yml的配置文件
SpringBoot打包发布
项目右键–>Run As…–>Maven Build…–>goals–>clean package
或者进入项目目录,命令行mvn clean package
如果报错没有主清单,在pom文件中新增下面代码
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<maimClass>com.majiaxueyuan.App</maimClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
最新文章
- noi 1.5 43:质因数分解
- AspNetUsers
- 推荐使用C++ 11
- 《深入浅出嵌入式底层软件开发》—1. ARM汇编编程基础
- Java反射机制学习
- 执行yiic webapp命令时报错:php.exe不是内部或外部命令,也不是可运行的程序
- 表单中GET与POST的区别
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->;用户管理模块新增“重置用户密码”功能
- 解决安卓JNI native 线程不能正常退出问题二
- Oracle 11g OGG 修改 trail 文件大小
- vb.net 水晶報表CrystalReport 動態設定資料庫來源
- openstack-云计算概述
- Python全栈问答小技巧_1
- AMQP &; JMS对比(转载)
- 索引唯一性扫描(INDEX UNIQUE SCAN)
- (原)luarocks更新某个模块
- Microsoft Dynamics CRM4.0 和 Microsoft Dynamics CRM 2011 JScript 方法对比
- Git之版本回退及回滚
- CSS节选——选择器
- jquery选择器详细说明