Is it possible to inject a bean into a spring form bean

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-04-21T21:34:08Z Indexed on 2010/04/22 0:43 UTC
Read the original article Hit count: 357

Filed under:
|
|
|

I tried to do it 2 different ways, but neither way worked.

@Component  
public class EmailForm{
...
private QuestionDAO questionDAO;
...
@Autowired
public void setQuestionDAO(QuestionDAO questionDAO) {
    this.questionDAO = questionDAO;
}
...

Another way:

@Component  
public class EmailForm implements ApplicationContextAware {
...
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.questionDAO = (QuestionDAO)applicationContext.getBean("questionDAO");
}
...

Neither way results in questionDAO being injected

Form bean is populated by spring:

@RequestMapping(method = RequestMethod.POST)
public String submit(@Valid final EmailForm emailForm, BindingResult result, final Model model) {

© Stack Overflow or respective owner

Related posts about java

Related posts about spring