我正在尝试使用两个不同的端口在Spring Boot中配置应用程序,但我还没有.我的第一个aproximation是两个控制器,我在两个控制器中用container.setPort(8080)定义了一个@Bean; 我的第二个aproximation已经添加了执行器依赖并改变了管理的端口,但我的应用程序没有运行."地址已在使用中:绑定",如何使用两个端口来配置应用程序?我想要一个端口用于管理员,另一个端口用于我的api的咨询.
我正在写一个Spring Boot App
我的要求是 - 在资源(src/main/resources)文件夹中,如果我添加新的xml文件..我应该阅读这些文件,并从每个文件中获取一些网址和其他特定设置.对于那些我需要每天下载数据的网址.所以新的调度程序作业将从url和一些设置开始
新作业将在不同的计划时间运行,这将使用xml文件中存在的cron表达式.还将在任何时间点动态添加文件如何实现它.
当 redis 关闭时,服务运行状况检查 api 响应 503。
{
"status": "DOWN",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 250790436864,
"free": 95412813824,
"threshold": 10485760
}
},
"db": {
"status": "UP",
"details": {
"database": "PostgreSQL",
"hello": 1
}
},
"refreshScope": {
"status": "UP"
},
"redis": {
"status": "DOWN",
"details": {
"error": "org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但实际上当redis宕机时服务是可用的。
服务状态可以不受redis状态影响吗?我还需要在健康检查 api 中查看 redis 详细信息。
我想,以确保端点Actuators内Spring Boot的项目.但是,使用准备运行Spring Security配置Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
Run Code Online (Sandbox Code Playgroud)
这太容易我需要Actuators使用我们的自定义安全性(此处为CASSSO).
第一次尝试是增加context-path了Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
context-path: /management
Run Code Online (Sandbox Code Playgroud)
并更新我的WebSecurityConfigurerAdapter配置
@Override
protected void configure(HttpSecurity http) throws Exception {
...
http.authorizeRequests()..antMatchers("/management/**").hasRole(Role.ADMINISTRATOR.toString());
...
}
Run Code Online (Sandbox Code Playgroud)
它工作但我必须硬编码Actuators context-path,所以当我想要更新时,management.context-path我必须更新我的安全性.
我知道可以检索价值management.context-path但是当价值等于时如何管理它""?
你可以回答我@Autowired EndpointHandlerMapping并检索Actuators端点列表......最后我将复制过去相同的逻辑ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter.
此外ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter @ConditionalOnMissingBean是指向自身,但是ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter内部静态受保护的类,所以不能在不传递参数的情况下禁用它management.security.enabled=false,这可能很奇怪,因为你的配置说management.security.enabled=false但实际上端点是安全的...... …
我正在使用Spring Boot应用程序,我使用Swagger作为文档.
我在我的应用程序中添加了Spring Boot Actuator,但现在我想在我的swagger文档中添加由执行器创建的新服务(/ health/metrics ..).
我没有找到如何配置Actuator和Swagger.
这是我的Spring Boot 1.5.1执行器application.properties:
#Spring Boot Actuator
management.contextPath: /actuator
management.security.roles=R_0
Run Code Online (Sandbox Code Playgroud)
这是我的WebSecurityConfig:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Value("${logout.success.url}")
private String logoutSuccessUrl;
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.addFilterBefore(new CorsFilter(), ChannelProcessingFilter.class);
http
.csrf().ignoringAntMatchers("/v1.0/**", "/logout")
.and()
.authorizeRequests()
.antMatchers("/oauth/authorize").authenticated()
//Anyone can access the urls
.antMatchers("/signin/**").permitAll()
.antMatchers("/v1.0/**").permitAll()
.antMatchers("/auth/**").permitAll()
.antMatchers("/actuator/health").permitAll()
.antMatchers("/actuator/**").hasAuthority("R_0")
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.failureUrl("/login?error=true")
.usernameParameter("username")
.passwordParameter("password")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl(logoutSuccessUrl)
.permitAll();
// @formatter:on
}
/**
* Configures …Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-boot spring-boot-actuator
我正在使用Spring Boot 2 M3执行器.默认情况下,运行状况端点映射到/application/health.
/health?我正在尝试使用 Micrometer.io 和 Spring Boot 2.0.0.RELEASE 来生成 Prometheus 指标。
当我尝试将 List 的大小公开为 Gauge 时,它一直显示 NaN。在文档中它说;
您有责任持有对您使用 Gauge 测量的状态对象的强引用。
我尝试了一些不同的方法,但我无法解决问题。这是我的一些试验代码。
import io.micrometer.core.instrument.*;
import io.swagger.backend.model.Product;
import io.swagger.backend.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@RestController
@RequestMapping("metrics")
public class ExampleController {
private AtomicInteger atomicInteger = new AtomicInteger();
private ProductService productService;
private final Gauge productGauge;
@Autowired
public HelloController(ProductService productService,
MeterRegistry registry) {
this.productService = productService;
createGauge("product_gauge", productService.getProducts(), registry);
}
private void createGauge(String metricName, List<Product> products,
MeterRegistry registry) {
List<Product> products = productService.getProducts();
// …Run Code Online (Sandbox Code Playgroud) 是否可以像health在“主”应用程序的单独线程池中那样处理执行器请求?
我为什么要问?我有一个应用程序,有时可能会用完所有可用线程,并且 Kubernetes 运行状况检查由于线程不可用来计算运行状况端点请求而失败。
我想确保无论应用程序承受多少负载,都会处理每个运行状况请求。
我正在考虑为执行器定义一个单独的线程池来操作,但我不知道如何做到这一点。
新手在这里,试图了解有关千分尺的更多信息。我目前正在探索如何实现这一点:
我正在使用启用了执行器和千分尺的 Spring boot 2。考虑以下类:
@Component
class MyService {
@Autowired
AuthorizeTransaction callbackTransaction;
@Autowired
AuthorizeTransaction immediateTransaction;
private MeterRegistry meterRegistry;
private Counter requestCounter;
private Counter responseCounter;
public MyService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
initCounters();
}
private initCounters() {
requestCounter = Counter.builder("iso_request")
.tags("mti", "0100") // how do I change the value of this tag for other request types like 0200, 0120, etc.,
.register(meterRegistry);
responseCounter = Counter.builder("iso_response")
.tags("mti", "0101")
.tags("response_code", "00") // how do I change the value of this tag for other response …Run Code Online (Sandbox Code Playgroud) spring-boot ×8
spring ×6
java ×4
micrometer ×2
health-check ×1
prometheus ×1
redis ×1
swagger ×1
threadpool ×1