-
1. Re: WebBeans is not just for JSF and EJB right?
nickarls Dec 11, 2008 7:45 AM (in response to rdelaplante)Gavin wrote a shiny new article called
Introduction to Web Beans
which can be found under theWeb Beans
link to the left, that will get you up to speed. OK, the specs have changed a little since then but mostly new features so it's still 95% current.I think the poster just speaks about a need for a general DI mechanism in Java SE so it's a different matter. There has been talk about the Web Beans binding types etc. would be useful in SE, too but it was targetted for EE (for now?).
When someone registers webbeanssuckusespring.org, we'll send out the full Department Of Truth ;-)
-
2. Re: WebBeans is not just for JSF and EJB right?
rdelaplante Dec 11, 2008 3:39 PM (in response to rdelaplante)Thanks. The
Introduction to WebBeans
is what I read (or skimmed). It doesn't show examples of unit testing WebBeans outside of the app server. Also, if I have two plain POJOs it is no longer clear if I can just inject one into the other without having to create a new annotation like @CreditCardProcessor, or if the dependency is automatically injeced without saying anything because anything and everything is a webbean. I want to see the most basic example without contextual scopes.public class NewsService() { private NewsDao dao; public NewsService(NewsDao dao) { this.dao = dao; } public List<NewsItem> getNews() { return dao.getNews(); } } public class NewsDao() { ... }
In Spring I would:
<bean id="newsDao" class="com.example.product.NewsDao"/> <bean id="newsService" class="com.example.product.NewsService"> <constructor-arg index="0" ref="newsDao"/> </bean>
I can inject newsService into another class using this XML config or annotations, or I can get a reference to a BeanFactory and ask it to give me a
newsService
.The last time I looked at Gavin's book/article it was not clear how to do this. There is no more @In annotation. There is no example of getting access to the WebBeans manager and asking it to give me an instance of
newsService
.I'll have to read it over again... but if someone can show me on here how to do that simple example I would be happy.
Thanks,
Ryan -
3. Re: WebBeans is not just for JSF and EJB right?
rdelaplante Dec 11, 2008 3:48 PM (in response to rdelaplante)I found some of what I'm looking for. It looks like @Current is the new @In, and that is all you need. No need to tell WebBeans that a POJO is a WebBean by annotating it or writing XML. This might work:
public class NewsService() { private NewsDao dao; public NewsService(@Current NewsDao dao) { this.dao = dao; } public List<NewsItem> getNews() { return dao.getNews(); } } public class NewsDao() { ... }
I'll have to do more reading to figure out how to make sure both Service an DAO are singletons.
I also found mention of the WebBeans Manager