提交 1b706f4a 编写于 作者: 武汉红喜's avatar 武汉红喜

可在非Web环境使用

上级 40d5e6f1
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
package org.hongxi.whatsmars.boot.sample.actuator; package org.hongxi.whatsmars.boot.sample.actuator;
import org.hongxi.whatsmars.boot.sample.actuator.filter.ActuatorFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -10,15 +11,21 @@ import org.springframework.security.config.annotation.web.WebSecurityConfigurer; ...@@ -10,15 +11,21 @@ import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
* Created by shenhongxi on 2020/7/17. * Created by shenhongxi on 2020/7/17.
*/ */
@Configuration @Configuration
@ConditionalOnWebApplication
public class ActuatorAutoConfiguration { public class ActuatorAutoConfiguration {
@Order(99) @Order(99)
@Bean @Bean
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public WebSecurityConfigurer standardWebSecurityConfigurer() { public WebSecurityConfigurer standardWebSecurityConfigurer() {
return new StandardWebSecurityConfigurer(); return new StandardWebSecurityConfigurer();
} }
@Bean
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public ActuatorFilter actuatorFilter() {
return new ActuatorFilter();
}
@Bean @Bean
public ActuatorReporter actuatorReporter() { public ActuatorReporter actuatorReporter() {
return new ActuatorReporter(); return new ActuatorReporter();
......
package org.hongxi.whatsmars.boot.sample.actuator.filter;
import org.springframework.http.HttpStatus;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by shenhongxi on 2020/8/13.
*/
public class ActuatorFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
// if (request.getServletPath().startsWith("/actuator")) {
// response.sendError(HttpStatus.FORBIDDEN.value());
// } else {
// filterChain.doFilter(request, response);
// }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册