[英]Postmapping annotation not working in spring boot application
GetMapping 有效,但后映射不起作用。 當我嘗試訪問 post 方法時,我得到 404。我嘗試使用 sysout 或 log 在其中寫入一些日志,但該方法不起作用。 下面的所有細節提前謝謝你。
我的 Controller:
@RestController
@RequestMapping("/")
@Slf4j
public class MainController {
@GetMapping("/gettest")
public String getTest(){
return "gettest w orking";
}
@PostMapping("/test")
public String testMet(@RequestBody String name) {
System.out.println("wttttf");
return "turnsomething";
}
我嘗試使用消耗和生產屬性,但不使用它們。 Getmapping 有效,但 postmapping 無效。 而且我還嘗試使用如下導入的jacksondatabind,因此我不需要消耗生成屬性但后映射不起作用。
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
我知道它是否與我的安全配置有關:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().and().cors().disable().authorizeRequests().antMatchers("/").permitAll().anyRequest()
.permitAll()
.and().exceptionHandling().accessDeniedPage("/error").and().logout().logoutUrl("/logout")
.clearAuthentication(true).invalidateHttpSession(true).deleteCookies("JSSESIONID","remember-me")
.logoutSuccessUrl("/").and().formLogin();
}
我認為您可以嘗試通過實現“配置(HttpSecurity http)”方法首先在 spring 安全配置 class 中禁用 csrf 來查看它是否仍然給出錯誤。
@EnableWebSecurity
public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.