package com.cloudtech.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import com.cloudtech.config.NettyConfig;
import com.cloudtech.server.Server;
import com.cloudtech.util.Consts;
@SpringBootApplication
@ComponentScan(value = {"com.cloudtech"})
public class Aws310Application implements CommandLineRunner {
protected static final Logger LOGGER = LoggerFactory.getLogger(Aws310Application.class);
@Autowired
NettyConfig nettyConfig;
public static void main(String[] args) {
new SpringApplicationBuilder(Aws310Application.class)
.web(WebApplicationType.NONE)
.run(args);
//SpringApplication.run(Aws310Application.class, args);
}
/**
* spring boot启动后,会进入该方法
*/
@Override
public void run(String... args) throws Exception {
init();
}
/**
* 初始化信息
*/
@SuppressWarnings("unused")
private void init() {
Consts.SERVER_PORT = nettyConfig.getPort();
Consts.MODULE_TYPE = nettyConfig.getModuleType();
}
}
可以通过main里面这样设置
这里代码实现了项目一启动就会初始化加载run()方法,用来做一些配置的读取
欢迎关注公众号,免费领取各种学习视频,学习相关java各个技术点面试知识,有相关学习疑问或者面试困惑也可以私信博主