3

I need to implement javax.faces.convert.Converter to convert String-to-Object and Object-to-String.

To do so, I have defined specific services (@Service), but I do not know how to get an instance.

I have tried to use @Autowired and @Component to get instance, but Spring is ignoring.

Is it possible to get @Service instance from FacesContext?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Valijon
  • 12,667
  • 4
  • 34
  • 67

1 Answers1

2

It's impossible. Spring annotations are useless if it didn't configure to use them in your applications.

First You should get the application context like this

ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());

Then use this context to get instance of the component.

YourService custB = (YourService )ctx.getBean("yourService");
Roman C
  • 49,761
  • 33
  • 66
  • 176