Мой контроллер:'Delete' метод не поддерживается Spring
@RequestMapping(value = "/list/{fn}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<Record> deleteUser(@PathVariable("fn") String filename) {
System.out.println("Fetching & Deleting data " + filename);
Record user1 = rep.findByfilename(filename);
if (user1 == null) {
System.out.println("Unable to delete." + filename + " not found");
return new ResponseEntity<Record>(HttpStatus.NOT_FOUND);
}
rep.deleteByfilename(filename);
return new ResponseEntity<Record>(HttpStatus.NO_CONTENT);
}
}
Мой код JS:
$scope.del = function (record) {
if (confirm('Do you really want to delete?')){
$http['delete']('/camera/list/' + record.filename).then(function() {
$scope.records.splice($scope.records.indexOf(record), 1);
});
}
};
Моя настройка доступа:
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/imageview", "/hello").access("hasRole('USER')")
.antMatchers("/camera/list").permitAll()
.antMatchers("/camera/store").permitAll()
.antMatchers("/camera/list/{fn}").permitAll()
.antMatchers("/imageview2", "/hello2").access("hasRole('ADMIN')").and()
.formLogin().and().exceptionHandling()
.accessDeniedPage("/access-denied");
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.and()
.logout()
.permitAll();
}
Погрешность я получаю это:
DELETE
XHR
http://localhost:8086/camera/list/a0c8918e4b088de4a5c7796e3eb11229 [HTTP/1.1 405 Method Not Allowed 22ms]
Сначала моя функция удаления может работать, но после того, как я использую весеннюю безопасность, я получил эту ошибку, которая не поддерживается. Кто-нибудь может помочь? Я попробовал поиск в Интернете, но не нашел решения.
У меня нет файла web.xml –
Затем в вашем классе, реализующем WebApplicationInitializer – Alexander
Создать новый новый класс? –