新增服务启动初始化控制配置
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 页面
|
* 默认 home 页面
|
||||||
*/
|
*/
|
||||||
private String defaultHomePage;
|
private String defaultHomePage;
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
private ServerInitProperties init;
|
||||||
|
|
||||||
public Integer getPort() {
|
public Integer getPort() {
|
||||||
return port;
|
return port;
|
||||||
@ -102,6 +106,14 @@ public class ServerProperties {
|
|||||||
this.defaultHomePage = defaultHomePage;
|
this.defaultHomePage = defaultHomePage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerInitProperties getInit() {
|
||||||
|
return init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInit(ServerInitProperties init) {
|
||||||
|
this.init = init;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder("{");
|
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.IInitBaseMenu;
|
||||||
import ink.wgink.interfaces.init.IInitBaseTable;
|
import ink.wgink.interfaces.init.IInitBaseTable;
|
||||||
import ink.wgink.interfaces.init.IInitBaseUser;
|
import ink.wgink.interfaces.init.IInitBaseUser;
|
||||||
|
import ink.wgink.properties.ServerProperties;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
@ -27,6 +28,8 @@ import java.util.Map;
|
|||||||
public class CommonStartup implements ApplicationRunner {
|
public class CommonStartup implements ApplicationRunner {
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
@Autowired
|
||||||
|
private ServerProperties serverProperties;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private IInitBaseMenu initBaseMenu;
|
private IInitBaseMenu initBaseMenu;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
@ -40,20 +43,25 @@ public class CommonStartup implements ApplicationRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
// 建表
|
if (serverProperties.getInit() == null || serverProperties.getInit().getTable()) {
|
||||||
Map<String, IInitBaseTable> initBaseTableMap = applicationContext.getBeansOfType(IInitBaseTable.class);
|
// 建表
|
||||||
for (Map.Entry<String, IInitBaseTable> kv : initBaseTableMap.entrySet()) {
|
Map<String, IInitBaseTable> initBaseTableMap = applicationContext.getBeansOfType(IInitBaseTable.class);
|
||||||
kv.getValue().createTable();
|
for (Map.Entry<String, IInitBaseTable> kv : initBaseTableMap.entrySet()) {
|
||||||
|
kv.getValue().createTable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 初始化菜单
|
if (serverProperties.getInit() == null || serverProperties.getInit().getMenu()) {
|
||||||
if (initBaseMenu != null) {
|
// 初始化菜单
|
||||||
initBaseMenu.init();
|
if (initBaseMenu != null) {
|
||||||
|
initBaseMenu.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 创建用户
|
if (serverProperties.getInit() == null || serverProperties.getInit().getUser()) {
|
||||||
if (initBaseUser != null) {
|
// 创建用户
|
||||||
initBaseUser.init();
|
if (initBaseUser != null) {
|
||||||
|
initBaseUser.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化环境变量
|
// 初始化环境变量
|
||||||
EnvManager envManager = EnvManager.getInstance();
|
EnvManager envManager = EnvManager.getInstance();
|
||||||
envManager.setEnvDao(envDao);
|
envManager.setEnvDao(envDao);
|
||||||
|
Loading…
Reference in New Issue
Block a user