![](/img/trans.png)
[英]Spring Boot Custom Authentication Provider with Java Configuration not working
[英]Spring Boot java configuration not working
我不确定这里发生了什么。 多年来,我一直在构建 spring 应用程序,感觉就像我错过了一些东西。
我有一个通过 spring 初始化程序创建的 spring 引导应用程序。 我像这样创建了一个配置 class 。
@Configuration
public class WfwwebConfiguration {
@Bean
public WebClient webClientBean() {
return new WebClient(MpesaPaymentService.MPESA_HOST, MpesaPaymentService.MPESA_PORT);
}
}
当然,这里的目标是自己创建我的 WebClient class。 问题是 spring 一直在上面运行无参数构造函数,它试图将 go 连接到 localhost。
所以我删除了那个构造函数,现在我的 spring 启动应用程序将无法启动,因为 WebClient 没有无参数构造函数。
那么我错过了什么? 我有
@SpringBootApplication
public class WfwwebApplication {
public static void main(String[] args) {
SpringApplication.run(WfwwebApplication.class, args);
}
}
应该打开自动配置,我所做的所有研究都表明它现在会自动选择配置 class 。
我仔细检查了我的@Configuration 以确保它没有从另一个库加载它。 ;)
想法?
请考虑以下工作最小示例,该示例将在启动时使用@Configuration
打印出“Hello,StackOverflow”,生成 object 的 class 和无参数构造函数。
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package org.example;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ApplicationConfiguration {
@Bean
public Greeter greeter() {
return new Greeter("StackOverflow");
}
}
package org.example;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class AppStartupRunner implements ApplicationRunner {
private final Greeter greeter;
public AppStartupRunner(Greeter greeter) {
this.greeter = greeter;
}
@Override
public void run(ApplicationArguments args) {
this.greeter.greet();
}
}
package org.example;
public class Greeter {
private final String name;
public Greeter(String name) {
this.name = name;
}
public void greet() {
System.out.println("Hello, " + this.name);
}
}
当我发现这个问题时,我正在 IntelliJ IDEA 环境中运行。 在尝试了很多事情之后,我尝试在运行配置中打开调试,但生成的消息没有任何帮助。
当我关闭设置并重新运行应用程序时,它开始自行完美运行。
如果这对其他人有帮助,请发表评论。 我很好奇是不是这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.