Spring Boot 项目部署
添加SpringApplicationBuilder方法
package com.yang;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@EnableWebSecurity
@SpringBootApplication
public class SpringbootBlogApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootBlogApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
创建上线环境远程配置
#远程配置
server:
port: 8086
spring:
datasource:
url: jdbc:mysql://xxx.xxx.xxx:3306/blog?serverTimezone=Asia/Shanghai
username: yj
driver-class-name: com.mysql.jdbc.Driver
# 密文密码
data-password: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
thymeleaf:
cache: false
mybatis:
type-aliases-package: com.yang.pojo
mapper-locations: classpath:mapper/*.xml
debug: true
注意事项:1.端口号必须在安全组中开通
2.debug=false
3.数据库连接配置正确
数据库连接navicat配置
打包springboot文件
这时就在target文件中得到了jar包
在阿里云上部署
现在所要做的就是将jar包放入ali的linux系统中,首先购买服务器,放通3306,808x端口(依据你在yaml文件中配置的)
我在此使用xftp软件将jar包放入
在linux中执行java -jar xxx.jar(xxx.jar即为包名),访问 地址:808x即可发现项目已经跑起来
如果显示java 环境未配置,从官网上下载jdk即可
执行nohup java -jar xxx.ja 只要服务器不关闭,项目就不会停止运行。