Questions tagged [jsr299]

Contexts and Dependency Injection for the Java EE platform

The specification: JSR 299

18 questions
338
votes
5 answers

Why use @PostConstruct?

In a managed bean, @PostConstruct is called after the regular Java object constructor. Why would I use @PostConstruct to initialize by bean, instead of the regular constructor itself?
Jan
  • 8,569
  • 11
  • 44
  • 52
16
votes
5 answers

How to inject String constants easily with Weld?

We have a situation where we provide an external configuration in form of a Map to our running programs. I have found that JSR-330 Dependency Injection gives a much cleaner way to use that configuration map in the code instead of passing the map…
Thorbjørn Ravn Andersen
  • 68,906
  • 28
  • 171
  • 323
7
votes
1 answer

How to inject beans from external libs with CDI?

How can I use JSR-299 CDI to inject (not annotated) beans from external libraries? Examples: Interface X and its implementations come from a third party lib. How can I decide which implementation to use? class A { @Inject private X…
deamon
  • 78,414
  • 98
  • 279
  • 415
6
votes
2 answers

Can Spring understand @Inject replacing Weld as a JSR-299 implementation?

I have noticed from several web pages that apparently Spring 3.0 supports @Inject from JSR-330. As we would really like to use JSR-299 syntax for dependency injection in our libraries for both web apps and stand-alone applications, and have…
Thorbjørn Ravn Andersen
  • 68,906
  • 28
  • 171
  • 323
6
votes
3 answers

how to instantiate more than one CDI/Weld bean for one class?

In Spring it was possible to instantiate any class by defining the corresponding bean in xml conf. It was also possible to instantiate more then one bean for the same class with different parameters..... Are the such features in CDI as well,…
smikesh
  • 1,141
  • 7
  • 26
6
votes
2 answers

Resolution of external (3rd party) beans in weld

I know it is still not quite popular, since the spec was released just a few months ago. I haven't "installed" weld yet, I'm just reading, and by this question I want to make sure I've understood this important point correct: Is resolution of beans…
Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121
5
votes
3 answers

How do I force usage of a CDI producer method?

Part of my problem here is using the proper vocabulary, so I apologize in advance for what might be a simple matter of terminology. Suppose I have a Person interface, and a PersonBean class that implements that interface. Suppose further I have a…
Laird Nelson
  • 12,770
  • 15
  • 64
  • 105
4
votes
2 answers

Whats the relationship between Spring and javax.enterprise.inject?

I was reading a Wikipedia article about Java EE application servers here: http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Java_EE_5_certified It says that 2 APIs that Java App Services implement…
HDave
  • 20,105
  • 26
  • 133
  • 216
3
votes
1 answer

Where should I declare my CDI resources?

JSR-299 (CDI) introduces the (unfortunately named) concept of a resource: http://docs.jboss.org/weld/reference/1.0.0/en-US/html/resources.html#d0e4373 You can think of a resource in this nomenclature as a bridge between the Java EE 6 brand of…
Laird Nelson
  • 12,770
  • 15
  • 64
  • 105
3
votes
1 answer

For CDI injection, do I need META-INF/beans.xml in the producer archive AND the injectee archive?

Perhaps it's just too many hours of combing through the CDI 1.0 specification, but I couldn't find a detailed description of exactly where a META-INF/beans.xml was required. (The section on bean discovery makes a few tantalizing statements that…
Laird Nelson
  • 12,770
  • 15
  • 64
  • 105
2
votes
1 answer

If my object is produced by a producer method, will its initializer methods be called automatically?

I have a producer method that creates instances of—let's say—Person. The instance that this method creates is of type PersonBean and quite obviously implements Person. This class has an initializer method in it: @Inject public void…
Laird Nelson
  • 12,770
  • 15
  • 64
  • 105
1
vote
3 answers

Fire event with subclass runtime type

I want to fire an event in CDI whose type I can only determine on runtime. For instance, let's say there's some interface A with implementing classes AA and AB. I have two observers: public void observeAA(@Observes AA aa) { } public void…
Artefacto
  • 90,634
  • 15
  • 187
  • 215
1
vote
2 answers

Why is the WebBeans (JSR-299) Conversation Context tied to JSF?

I am reading through the Public Review Draft of the Web Beans specification (JSR-299) and I am wondering why it is so 'tightly coupled' to JSF? Especially the Conversation Context seems only be specified for JSF. I understand, that it is a goal of…
jbandi
  • 14,967
  • 8
  • 62
  • 75
1
vote
2 answers

Errai, CDI, Netbeans warnings and beans.xml

Is there any easy way to remove these nasty Netbeans warnings about "Unsatisfied dependency: no bean matches the injection point"? The problem is that the GWT and Errai packages do NOT contain beans.xml files and therefore do not contain activated…
user1050755
  • 9,463
  • 3
  • 35
  • 51
1
vote
2 answers

How to inject objects of the same class with different scopes?

In terms of simplicity and correctness, what is the best way to inject objects of the same class with different scopes? In a servlet I want to have injected objects of the same class with different scopes. Still don't know if going to use…
user454322
  • 6,174
  • 4
  • 38
  • 49
1
2