初始化项目
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package xtools.app;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.util.StopWatch;
|
||||
import xtools.boot.core.utils.AppUtils;
|
||||
|
||||
/**
|
||||
* <p>Title : MonitorApplication</p>
|
||||
* <p>Description : MonitorApplication</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/01/17 12:30
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableAdminServer
|
||||
@SpringBootApplication
|
||||
public class MonitorApplication {
|
||||
|
||||
/**
|
||||
* Main
|
||||
*
|
||||
* @param args 参数
|
||||
*/
|
||||
static void main(String[] args) {
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start();
|
||||
runApp(args);
|
||||
sw.stop();
|
||||
log.info(AppUtils.info(sw.getTotalTimeMillis()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行App
|
||||
*
|
||||
* @param args 参数
|
||||
*/
|
||||
public static void runApp(String[] args) {
|
||||
SpringApplication.run(MonitorApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package xtools.app.monitor.boot.config;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.AdminServerProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
|
||||
/**
|
||||
* <p>Title : SecurityConfig</p>
|
||||
* <p>Description : SecurityConfig</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/01/17 12:30
|
||||
*/
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
/**
|
||||
* Admin配置信息
|
||||
**/
|
||||
private final String adminContextPath;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param adminServerProperties AdminServer配置信息
|
||||
*/
|
||||
public SecurityConfig(AdminServerProperties adminServerProperties) {
|
||||
this.adminContextPath = adminServerProperties.getContextPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Security过滤链
|
||||
*
|
||||
* @param httpSecurity HttpSecurity
|
||||
* @return Security过滤链
|
||||
*/
|
||||
@Bean
|
||||
SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) {
|
||||
// 登录成功处理类
|
||||
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
successHandler.setTargetUrlParameter("redirectTo");
|
||||
successHandler.setDefaultTargetUrl(adminContextPath + "/");
|
||||
|
||||
// 无需授权的资源
|
||||
String[] urls = {
|
||||
// 静态文件
|
||||
adminContextPath + "/assets/**",
|
||||
// 登录页面
|
||||
adminContextPath + "/login"
|
||||
};
|
||||
|
||||
httpSecurity
|
||||
.headers(header -> header.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
|
||||
// 授权机制
|
||||
.authorizeHttpRequests(auth -> auth.requestMatchers(urls).permitAll().anyRequest().authenticated())
|
||||
// 登录页面配置,用于替换security默认页面
|
||||
.formLogin(req -> req.loginPage(adminContextPath + "/login").successHandler(successHandler))
|
||||
// 登出页面配置,用于替换security默认页面
|
||||
.logout(req -> req.logoutUrl(adminContextPath + "/logout"))
|
||||
// 启用httpBasic认证模式
|
||||
.httpBasic(httpBasic -> {
|
||||
})
|
||||
// 禁用csrf
|
||||
.csrf(AbstractHttpConfigurer::disable);
|
||||
return httpSecurity.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
spring:
|
||||
boot:
|
||||
admin:
|
||||
# UI配置
|
||||
ui:
|
||||
# 页面标题
|
||||
title: ${MONITOR_UI_TITLE:xToolsMonitor}
|
||||
# 导航栏中显示的品牌
|
||||
brand: ${MONITOR_UI_BRAND:xToolsMonitor}
|
||||
@@ -0,0 +1,15 @@
|
||||
# App信息
|
||||
info:
|
||||
app:
|
||||
# 作者
|
||||
author: '@project.organization.name@'
|
||||
# 项目名
|
||||
name: '@project.artifactId@'
|
||||
# 版本号
|
||||
version: '@project.version@'
|
||||
# 项目编码
|
||||
encoding: '@project.build.sourceEncoding@'
|
||||
# Url
|
||||
url: '@project.organization.url@'
|
||||
# Java版本
|
||||
java: '@java.version@'
|
||||
@@ -0,0 +1,35 @@
|
||||
# Spring 信息
|
||||
spring:
|
||||
cloud:
|
||||
# Nacos 配置信息
|
||||
nacos:
|
||||
# Nacos 发现配置信息
|
||||
discovery:
|
||||
# Nacos 发现服务器地址
|
||||
server-addr: ${NACOS_SERVICE_HOST:127.0.0.1}:${NACOS_SERVICE_PORT:8848}
|
||||
# Nacos 发现服务器用户名
|
||||
username: ${NACOS_SERVICE_USERNAME:nacos}
|
||||
# Nacos 发现服务器密码
|
||||
password: ${NACOS_SERVICE_PASSWORD:nacos}
|
||||
# Nacos 发现服务器命名空间(默认为Public),可以省略不写
|
||||
namespace: ${NACOS_DISCOVERY_NAMESPACE:xtools-cloud}
|
||||
# 仅ipv4模式
|
||||
ip-type: IPv4
|
||||
# Nacos 配置中心信息
|
||||
config:
|
||||
# Nacos 配置服务器地址
|
||||
server-addr: ${NACOS_SERVICE_HOST:127.0.0.1}:${NACOS_SERVICE_PORT:8848}
|
||||
# Nacos 配置服务器用户名
|
||||
username: ${NACOS_SERVICE_USERNAME:nacos}
|
||||
# Nacos 配置服务器密码
|
||||
password: ${NACOS_SERVICE_PASSWORD:nacos}
|
||||
# Nacos 配置服务器命名空间(默认为Public),可以省略不写
|
||||
namespace: ${NACOS_CONFIG_NAMESPACE:xtools-cloud}
|
||||
# 配置文件
|
||||
config:
|
||||
import:
|
||||
# Boot配置文件
|
||||
- nacos:application-boot-log.yaml?refreshEnabled=true&group=BOOT
|
||||
- nacos:application-boot-monitor.yaml?refreshEnabled=true&group=BOOT
|
||||
# App配置文件
|
||||
- nacos:application-app-monitor.yaml?refreshEnabled=true&group=APP
|
||||
@@ -0,0 +1,16 @@
|
||||
# Spring 配置
|
||||
spring:
|
||||
# 应用配置
|
||||
application:
|
||||
# 应用名称
|
||||
name: xtools-app-monitor
|
||||
# 环境配置
|
||||
profiles:
|
||||
active:
|
||||
- info
|
||||
- nacos
|
||||
|
||||
# 服务器配置
|
||||
server:
|
||||
# 端口
|
||||
port: ${MONITOR_SERVICE_PORT:18100}
|
||||
Reference in New Issue
Block a user