Spring Boot Admin 集成

master
chenyuepan 3 weeks ago
parent d9d073bcd6
commit d3b643c363

@ -49,7 +49,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.keycloak</groupId>-->
<!-- <artifactId>keycloak-spring-boot-starter</artifactId>-->
<!-- <version>14.0.0</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.mysql</groupId> <groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
@ -161,11 +165,6 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.7.12</version>
</dependency>
<!-- excel文件导出 --> <!-- excel文件导出 -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
@ -218,8 +217,21 @@
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.5.0</version> <version>4.5.0</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- 封装了各大模型的交互接口 --> <!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-actuator</artifactId>-->
<!-- </dependency>-->
<!-- Spring Boot Admin Client -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>3.0.2</version>
</dependency>
<!-- Metrics -->
<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-registry-prometheus</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>io.springboot.ai</groupId>--> <!-- <groupId>io.springboot.ai</groupId>-->
<!-- <artifactId>spring-ai-openai-spring-boot-starter</artifactId>--> <!-- <artifactId>spring-ai-openai-spring-boot-starter</artifactId>-->

@ -13,8 +13,6 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser; import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext; import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
@ -29,7 +27,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays;
@Aspect @Aspect
@Component @Component

@ -8,6 +8,7 @@ import com.example.venue_reservation_service.utils.RedisUtil;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@ -22,6 +23,8 @@ public class CacheInitializer {
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
private final static String REDIS_KEY = "sensitive-word"; private final static String REDIS_KEY = "sensitive-word";
@PostConstruct // 在Bean初始化后执行[5](@ref) @PostConstruct // 在Bean初始化后执行[5](@ref)

@ -0,0 +1,30 @@
package com.example.venue_reservation_service.config;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
// 所有请求都无需认证
.anyRequest().permitAll()
)
.formLogin(AbstractHttpConfigurer::disable // 禁用表单登录
)
.httpBasic(AbstractHttpConfigurer::disable // 禁用 HTTP Basic
)
.csrf(AbstractHttpConfigurer::disable // 开发环境建议禁用 CSRF
);
return http.build();
}
}

@ -1,7 +1,7 @@
server: server:
port: 9020 port: 9020
# servlet: # servlet:
# context-path: /api # context-path: /
netty: netty:
port: 9030 port: 9030
@ -50,6 +50,35 @@ spring:
max-interval: 10000ms max-interval: 10000ms
max-attempts: 3 max-attempts: 3
multiplier: 2 multiplier: 2
security:
user:
name: admin
password: admin123
roles: ADMIN
boot:
admin:
client:
url: http://localhost:10020/ # 服务端地址
username: admin # 服务端用户名
password: admin123! # 服务端密码
# 暴露完整监控端点
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
info:
enabled: true
metrics:
enabled: true
loggers:
enabled: true
server:
port: ${server.port}
# knife4j的增强配置不需要增强可以不配 # knife4j的增强配置不需要增强可以不配
knife4j: knife4j:
enable: true # 开启knife4j,无需添加@EnableKnife4j注解 enable: true # 开启knife4j,无需添加@EnableKnife4j注解

Loading…
Cancel
Save