![](/img/trans.png)
[英]How to programatically register an instance of a FactoryBean in Spring
[英]Howto get @Service instance in Spring programatically
我需要實現javax.faces.convert.Converter
才能將String-to-Object和Object-to-String轉換。
為此,我已經定義了特定的服務( @Service
),但是我不知道如何獲取實例。
我試圖使用@Autowired
和@Component
來獲取實例,但是Spring忽略了。
是否可以從FacesContext
獲取@Service
實例?
不可能。 如果未將Spring批注配置為在您的應用程序中使用它們,則它們將無用。
首先,您應該獲得這樣的應用程序上下文
ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
然后使用此上下文獲取組件的實例。
YourService custB = (YourService )ctx.getBean("yourService");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.