Я хотел бы использовать класс RepositoryEntityLinks, чтобы получить ссылку на ресурс в различных местах в моем коде, как указано в разделе 12.1 текущего руководства Spring Data RestИспользование Spring Data Rest RepositoryEntityLinks вне контроллера
12.1. Programmatic Links Sometimes you need to add links to exported resources in your own custom built Spring MVC controllers. There are three basic levels of linking available:
...
3 Using Spring Data REST’s implementation of RepositoryEntityLinks.
http://docs.spring.io/spring-data/rest/docs/current/reference/html/#_programmatic_links
Я отмечаю, что документы прямо ссылаются на «... собственные настраиваемые контроллеры Spring MVC», и, похоже, это единственное место, где оно доступно. Я хотел бы использовать настроенный экземпляр в Spring Security AuthenticationSuccessHandler однако приложение не запускается с ошибкой:
Нет квалификационные рожкового типа [org.springframework.data.rest.webmvc.support.RepositoryEntityLinks] найдено
Я смог успешно ввести его в контроллер, как и ожидалось.
Могу ли я использовать класс RepositoryEntityLinks за пределами Spring MVC Controller?
public class RestAuthenticationSuccessHandler implements AuthenticationSuccessHandler
{
@Autowired
private RepositoryEntityLinks entityLinks;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException
{
//do something with entityLinks
}
}