正如我们所说,我尝试将旧项目迁移到最新版本的 Spring Boot(又名 3.1.2)。但是,由于弃用,以下代码段的 .csrf() 和 .requiresChannel() 方法不再起作用。
我找不到替代它们的方法。你能帮我吗?
@Configuration
@EnableWebSecurity
public class ApplicationSecurityConfig {
private final ApplicationUserService applicationUserService;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
public ApplicationSecurityConfig(
ApplicationUserService applicationUserService,
BCryptPasswordEncoder bCryptPasswordEncoder) {
this.applicationUserService = applicationUserService;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}
@Bean
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.requiresChannel()
.antMatchers("/actuator/**")
.requiresInsecure()
.and()
.authorizeRequests()
.antMatchers(
"/api/v*/registration/**",
"/register*",
"/login",
"/actuator/**").permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("email")
.permitAll()
.defaultSuccessUrl("/",true)
.failureUrl("/login-error")
.and()
.logout()
.logoutUrl("/logout")
.clearAuthentication(true)
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID","Idea-2e8e7cee")
.logoutSuccessUrl("/login");
return http.build();
}
@Bean
public AuthenticationManager authenticationManager( …Run Code Online (Sandbox Code Playgroud) 您好,我在 Spring Boot 中有一个应用程序,我正在公开 Prometheus 上的一些指标。我的下一个目标是在 Grafana 上提供这些指标,以获得一些漂亮的仪表板。我在 WSL Ubuntu 上使用 docker,并为 Prometheus 和 Grafana 输入以下命令:
docker run -d --name=prometheus -p 9090:9090 -v /mnt/d/Projects/Msc-Thesis-Project/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml
Run Code Online (Sandbox Code Playgroud)
docker run -d --name=grafana -p 3000:3000 grafana/grafana
Run Code Online (Sandbox Code Playgroud)
下面我在浏览器中为您提供了 Prometheus 仪表板,如您所见,一切都已启动并正在运行。我的问题是在 Grafana 配置中,我必须将 Prometheus 配置为数据源。
在 URL 字段中,我提供了 http://localhost:9090 但出现以下错误:
读取 Prometheus 时出错:发布“http://localhost:9090/api/v1/query”:拨打 tcp 127.0.0.1:9090:连接:连接被拒绝
我到处搜索,发现一些不适用于我的解决方法。具体来说,我使用了以下内容:http://host.docker.internal:9090、http://server-ip:9090,当然还有通过 ipconfig 命令 http://<ip_address>:9090 获得的系统 IP 地址。没有任何作用!
我没有使用 docker-compose,而只是使用 prometheus.yml 文件,如下所示。
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: …Run Code Online (Sandbox Code Playgroud) 我正在使用数组列表通过构建一个交互式菜单供用户选择来存储来自用户输入的值。到目前为止,我的两个选择是为用户提供向列表输入数据和读取列表的全部内容。到目前为止,我创建的代码由两个类组成。
我的主课,
package com.andrekreou;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to the personnel address book");
System.out.println("In the following menu, a whole selection of services is provided");
Scanner user_input = new Scanner(System.in);
while (true){
showMenu();
String selection = user_input.next();
if (selection.equals("1")){
System.out.println("Below you can see all of the data being provided");
for (String personnel : catalog) { } //ERROR: Cannot resolve symbol catalog
}else if (selection.equals("2")){
ArrayList<String> catalog = new ArrayList<>();
Personnel …Run Code Online (Sandbox Code Playgroud)