安全配置类
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConf {
@Bean
public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
}
Run Code Online (Sandbox Code Playgroud)
控制器
@RestController
public class Controller {
@GetMapping("/test")
public String test(){
return "test";
}
}
Run Code Online (Sandbox Code Playgroud)
测试班
@ExtendWith(SpringExtension.class)
@WebMvcTest(controllers = Controller.class)
@ComponentScan("com.example.demo")
public class DemoApplicationTests {
@Test
public void test() {
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个简单的应用程序,如果我尝试启动主应用程序,它可以工作,但是当我启动测试类时,我收到此错误:
java.lang.StackOverflowError
at java.base/java.lang.StackTraceElement.of(StackTraceElement.java:526)
at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:828)
at java.base/java.lang.Throwable.getStackTrace(Throwable.java:820)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:79)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89) …Run Code Online (Sandbox Code Playgroud)