新增Springboot admin配置

master
barney 2 years ago
parent ee560a4675
commit c20451c67c
  1. 5
      Email/pom.xml
  2. 44
      Email/src/main/java/cc/bnblogs/email/config/SecuritySecureConfig.java
  3. 14
      Email/src/main/resources/application.yml
  4. 89
      JsonStudy/logs/info.log
  5. 39
      JsonStudy/src/main/resources/application.yml

@ -68,6 +68,11 @@
<version>2.7.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>

@ -0,0 +1,44 @@
package cc.bnblogs.email.config;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
//1.配置所有静态资源和登录页可以公开访问
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
//2.配置登录和登出路径
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
//3.开启http basic支持,admin-client注册时需要使用
.httpBasic().and()
.csrf()
//4.开启基于cookie的csrf保护
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
//5.忽略这些路径的csrf保护以便admin-client注册
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
}
}

@ -4,6 +4,7 @@ spring:
password: zfp251217
url: jdbc:mysql://192.168.153.135:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
mail:
host: smtp.163.com
username: 15270405776@163.com
@ -15,16 +16,19 @@ spring:
starttls:
enable: true
required: true
security:
user:
name: admin
password: 123456
boot:
admin:
client:
url: 'http://localhost:8000/admin-server'
context-path: '/admin-server'
security:
user:
name: admin
password: 123456
notify:
mail:
from: 15270405776@163.com
to: 1337425156@qq.com
# 当前项目端口号
server:
port: 8000

@ -0,0 +1,89 @@
2023-03-20 16:11:15.636 INFO 15984 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Starting JsonStudyApplication using Java 1.8.0_342 on DESKTOP-G5S5LHL with PID 15984 (D:\spring_study\JsonStudy\target\classes started by 15270 in D:\spring_study\JsonStudy)
2023-03-20 16:11:15.637 INFO 15984 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-20 16:11:15.675 INFO 15984 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-03-20 16:11:15.675 INFO 15984 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-03-20 16:11:16.569 INFO 15984 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2023-03-20 16:11:16.570 INFO 15984 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
2023-03-20 16:11:16.570 INFO 15984 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2023-03-20 16:11:16.570 INFO 15984 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2023-03-20 16:11:16.574 INFO 15984 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
2023-03-20 16:11:16.580 INFO 15984 --- [restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-20 16:11:16.580 INFO 15984 --- [restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-20 16:11:16.634 INFO 15984 --- [restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-20 16:11:16.634 INFO 15984 --- [restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 958 ms
2023-03-20 16:11:17.141 WARN 15984 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
2023-03-20 16:11:17.145 INFO 15984 --- [restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 15 endpoint(s) beneath base path '/actuator'
2023-03-20 16:11:17.182 INFO 15984 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2023-03-20 16:11:17.195 INFO 15984 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Started JsonStudyApplication in 1.944 seconds (JVM running for 2.899)
2023-03-20 16:11:18.477 INFO 15984 --- [RMI TCP Connection(3)-192.168.153.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-03-20 16:11:18.477 INFO 15984 --- [RMI TCP Connection(3)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-03-20 16:11:18.478 INFO 15984 --- [RMI TCP Connection(3)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-03-20 16:11:26.533 INFO 15984 --- [registrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Application registered itself as 40af63bed8ea
2023-03-20 16:17:54.231 INFO 15984 --- [Thread-18] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-03-20 16:17:54.232 INFO 15984 --- [Thread-18] o.a.c.c.C.[Tomcat].[localhost].[/] : Destroying Spring FrameworkServlet 'dispatcherServlet'
2023-03-20 16:20:45.675 INFO 19636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Starting JsonStudyApplication using Java 1.8.0_342 on DESKTOP-G5S5LHL with PID 19636 (D:\spring_study\JsonStudy\target\classes started by 15270 in D:\spring_study\JsonStudy)
2023-03-20 16:20:45.676 INFO 19636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-20 16:20:45.715 INFO 19636 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-03-20 16:20:45.715 INFO 19636 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-03-20 16:20:46.547 INFO 19636 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2023-03-20 16:20:46.547 INFO 19636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
2023-03-20 16:20:46.547 INFO 19636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2023-03-20 16:20:46.547 INFO 19636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2023-03-20 16:20:46.551 INFO 19636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
2023-03-20 16:20:46.556 INFO 19636 --- [restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-20 16:20:46.556 INFO 19636 --- [restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-20 16:20:46.605 INFO 19636 --- [restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-20 16:20:46.605 INFO 19636 --- [restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 890 ms
2023-03-20 16:20:47.032 WARN 19636 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
2023-03-20 16:20:47.035 INFO 19636 --- [restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 15 endpoint(s) beneath base path '/actuator'
2023-03-20 16:20:47.126 INFO 19636 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2023-03-20 16:20:47.138 INFO 19636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Started JsonStudyApplication in 1.835 seconds (JVM running for 2.699)
2023-03-20 16:20:48.088 INFO 19636 --- [RMI TCP Connection(2)-192.168.153.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-03-20 16:20:48.088 INFO 19636 --- [RMI TCP Connection(2)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-03-20 16:20:48.089 INFO 19636 --- [RMI TCP Connection(2)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-03-20 16:20:56.523 INFO 19636 --- [registrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Application registered itself as 40af63bed8ea
2023-03-20 16:21:15.332 INFO 19636 --- [Thread-17] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-03-20 16:21:15.333 INFO 19636 --- [Thread-17] o.a.c.c.C.[Tomcat].[localhost].[/] : Destroying Spring FrameworkServlet 'dispatcherServlet'
2023-03-20 16:36:16.631 INFO 1636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Starting JsonStudyApplication using Java 1.8.0_342 on DESKTOP-G5S5LHL with PID 1636 (D:\spring_study\JsonStudy\target\classes started by 15270 in D:\spring_study\JsonStudy)
2023-03-20 16:36:16.632 INFO 1636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-20 16:36:16.665 INFO 1636 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-03-20 16:36:16.665 INFO 1636 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-03-20 16:36:17.479 INFO 1636 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2023-03-20 16:36:17.479 INFO 1636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
2023-03-20 16:36:17.480 INFO 1636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2023-03-20 16:36:17.480 INFO 1636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2023-03-20 16:36:17.482 INFO 1636 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
2023-03-20 16:36:17.488 INFO 1636 --- [restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-20 16:36:17.488 INFO 1636 --- [restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-20 16:36:17.560 INFO 1636 --- [restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-20 16:36:17.560 INFO 1636 --- [restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 895 ms
2023-03-20 16:36:18.036 WARN 1636 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
2023-03-20 16:36:18.039 INFO 1636 --- [restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 15 endpoint(s) beneath base path '/actuator'
2023-03-20 16:36:18.088 INFO 1636 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2023-03-20 16:36:18.144 INFO 1636 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Started JsonStudyApplication in 1.825 seconds (JVM running for 2.669)
2023-03-20 16:36:18.596 INFO 1636 --- [RMI TCP Connection(4)-192.168.153.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-03-20 16:36:18.596 INFO 1636 --- [RMI TCP Connection(4)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-03-20 16:36:18.597 INFO 1636 --- [RMI TCP Connection(4)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-03-20 16:36:27.243 INFO 1636 --- [registrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Application registered itself as 40af63bed8ea
2023-03-20 16:47:54.721 WARN 1636 --- [registrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Failed to register application as Application(name=spring-boot-admin-client-1, managementUrl=http://DESKTOP-G5S5LHL:9000/actuator, healthUrl=http://DESKTOP-G5S5LHL:9000/actuator/health, serviceUrl=http://DESKTOP-G5S5LHL:9000/) at spring-boot-admin ([http://localhost:8000/admin-server/instances]): I/O error on POST request for "http://localhost:8000/admin-server/instances": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect. Further attempts are logged on DEBUG level
2023-03-20 16:51:01.130 INFO 20756 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Starting JsonStudyApplication using Java 1.8.0_342 on DESKTOP-G5S5LHL with PID 20756 (D:\spring_study\JsonStudy\target\classes started by 15270 in D:\spring_study\JsonStudy)
2023-03-20 16:51:01.131 INFO 20756 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-20 16:51:01.168 INFO 20756 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-03-20 16:51:01.168 INFO 20756 --- [restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-03-20 16:51:02.042 INFO 20756 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2023-03-20 16:51:02.043 INFO 20756 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
2023-03-20 16:51:02.043 INFO 20756 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2023-03-20 16:51:02.043 INFO 20756 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2023-03-20 16:51:02.045 INFO 20756 --- [restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
2023-03-20 16:51:02.051 INFO 20756 --- [restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-20 16:51:02.051 INFO 20756 --- [restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-20 16:51:02.104 INFO 20756 --- [restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-20 16:51:02.104 INFO 20756 --- [restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 935 ms
2023-03-20 16:51:02.558 WARN 20756 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
2023-03-20 16:51:02.562 INFO 20756 --- [restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 15 endpoint(s) beneath base path '/actuator'
2023-03-20 16:51:02.650 INFO 20756 --- [restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2023-03-20 16:51:02.661 INFO 20756 --- [restartedMain] c.b.jsonstudy.JsonStudyApplication : Started JsonStudyApplication in 1.963 seconds (JVM running for 2.871)
2023-03-20 16:51:03.449 INFO 20756 --- [RMI TCP Connection(3)-192.168.153.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-03-20 16:51:03.449 INFO 20756 --- [RMI TCP Connection(3)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-03-20 16:51:03.450 INFO 20756 --- [RMI TCP Connection(3)-192.168.153.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-03-20 16:51:12.023 INFO 20756 --- [registrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Application registered itself as 40af63bed8ea

@ -4,27 +4,38 @@ spring:
password: zfp251217
url: jdbc:mysql://192.168.153.135:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
#这里配置admin server 的地址
boot:
admin:
client:
url: http://localhost:8000/admin-server
url: http://localhost:8000/admin-server #要注册的server端的url地址
username: admin #连接服务端的账号和密码
password: 123456
application:
name: spring-boot-admin-client-1
# 本项目端口
server:
port: 9000
#开放端点用于SpringBoot Admin的监控
management:
endpoint:
shutdown:
enabled: true #开启端点
health:
show-details: always # 是否展示健康检查详情
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
include: '*' # 暴露所有端点
health:
ldap:
enabled: false #关闭对ldap的健康检查
# 本项目端口
server:
port: 9000
# 配置日志文件路径,springAdmin服务端可实时查看
logging:
file:
name: logs/info.log
info:
app:
name: "@project.name@"
description: "@project.description@"
version: "@project.version@"
spring-boot-version: "@project.parent.version@"
Loading…
Cancel
Save