Использование bean-компонентов Spring внутри Rest @ControllerJAVA

Программисты JAVA общаются здесь
Anonymous
Использование bean-компонентов Spring внутри Rest @Controller

Сообщение Anonymous »

после перехода с Spring 3 на 5 я больше не могу делать это в контроллере отдыха:

Код: Выделить всё

@Lazy
@Controller
@RequestMapping("/Portability4CtRestService")
public class Portability4CtRestService extends AbstractP4CtRestService {

private P4CtAccountRoutingService accountRoutingService;

/**
* @param accountRoutingService the accountRoutingService to set
*/
@Autowired
public void setAccountRoutingService(P4CtAccountRoutingService p4ctAccountRoutingService) {
this.accountRoutingService = p4ctAccountRoutingService;
}

@RequestMapping(value = "/searchAccountRouting", method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" })
public @ResponseBody
String searchAccountRouting(HttpServletRequest request) {

//do something with accountRoutingService....

}
}
объект, автоматически связанный с аннотацией @Autowired, всегда имеет значение null, то же самое происходит, если я использую

Код: Выделить всё

@Autowired
private P4CtAccountRoutingService accountRoutingService;

or

@Resources
private P4CtAccountRoutingService accountRoutingService;
Возможный обходной путь — сделать в конструкторе что-то вроде этого:

Код: Выделить всё

public Portability4CtRestService() {
setAccountRoutingService((P4CtAccountRoutingService) it.vtfinance.vtpie.core.configuration.spring.ContextSupport.getContext().getBean(P4CtAccountRoutingService.BEAN_NAME));
}
Но мне интересно, правильный ли это путь и почему я больше не могу использовать аннотацию Spring для вызова Spring Bean.

Подробнее здесь: https://stackoverflow.com/questions/787 ... controller

Вернуться в «JAVA»