新增服务启动初始化控制配置
This commit is contained in:
parent
7e43419034
commit
abe91b18eb
@ -0,0 +1,38 @@
|
||||
package ink.wgink.properties;
|
||||
|
||||
/**
|
||||
* @Description: 服务初始化配置
|
||||
* @Author: WenG
|
||||
* @Date: 2022/5/16 22:54
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class ServerInitProperties {
|
||||
|
||||
private Boolean table;
|
||||
private Boolean menu;
|
||||
private Boolean user;
|
||||
|
||||
public Boolean getTable() {
|
||||
return table == null ? true : table;
|
||||
}
|
||||
|
||||
public void setTable(Boolean table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public Boolean getMenu() {
|
||||
return menu == null ? true : menu;
|
||||
}
|
||||
|
||||
public void setMenu(Boolean menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public Boolean getUser() {
|
||||
return user == null ? true : user;
|
||||
}
|
||||
|
||||
public void setUser(Boolean user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
@ -45,6 +45,10 @@ public class ServerProperties {
|
||||
* 默认 home 页面
|
||||
*/
|
||||
private String defaultHomePage;
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private ServerInitProperties init;
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
@ -102,6 +106,14 @@ public class ServerProperties {
|
||||
this.defaultHomePage = defaultHomePage;
|
||||
}
|
||||
|
||||
public ServerInitProperties getInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public void setInit(ServerInitProperties init) {
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
|
@ -5,6 +5,7 @@ import ink.wgink.common.manager.env.EnvManager;
|
||||
import ink.wgink.interfaces.init.IInitBaseMenu;
|
||||
import ink.wgink.interfaces.init.IInitBaseTable;
|
||||
import ink.wgink.interfaces.init.IInitBaseUser;
|
||||
import ink.wgink.properties.ServerProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
@ -27,6 +28,8 @@ import java.util.Map;
|
||||
public class CommonStartup implements ApplicationRunner {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
@Autowired(required = false)
|
||||
private IInitBaseMenu initBaseMenu;
|
||||
@Autowired(required = false)
|
||||
@ -40,20 +43,25 @@ public class CommonStartup implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
// 建表
|
||||
Map<String, IInitBaseTable> initBaseTableMap = applicationContext.getBeansOfType(IInitBaseTable.class);
|
||||
for (Map.Entry<String, IInitBaseTable> kv : initBaseTableMap.entrySet()) {
|
||||
kv.getValue().createTable();
|
||||
if (serverProperties.getInit() == null || serverProperties.getInit().getTable()) {
|
||||
// 建表
|
||||
Map<String, IInitBaseTable> initBaseTableMap = applicationContext.getBeansOfType(IInitBaseTable.class);
|
||||
for (Map.Entry<String, IInitBaseTable> kv : initBaseTableMap.entrySet()) {
|
||||
kv.getValue().createTable();
|
||||
}
|
||||
}
|
||||
// 初始化菜单
|
||||
if (initBaseMenu != null) {
|
||||
initBaseMenu.init();
|
||||
if (serverProperties.getInit() == null || serverProperties.getInit().getMenu()) {
|
||||
// 初始化菜单
|
||||
if (initBaseMenu != null) {
|
||||
initBaseMenu.init();
|
||||
}
|
||||
}
|
||||
// 创建用户
|
||||
if (initBaseUser != null) {
|
||||
initBaseUser.init();
|
||||
if (serverProperties.getInit() == null || serverProperties.getInit().getUser()) {
|
||||
// 创建用户
|
||||
if (initBaseUser != null) {
|
||||
initBaseUser.init();
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化环境变量
|
||||
EnvManager envManager = EnvManager.getInstance();
|
||||
envManager.setEnvDao(envDao);
|
||||
|
Loading…
Reference in New Issue
Block a user