Is weld resolving producers methods for injecting right?
jotraverso Jun 19, 2012 6:49 AMHi all,
I'm working on JBoss 7.0.1.Final + Java 1.6.0_30 + Eclipse Indigo + JBoss Tools and after a few months deeping into EE 6 with this stack I get amazed with this case.
I have a few components and I want to put it all into a WAR, but I want to set up a few alternative producer methods, because I'm testing and, for example, I don't have an Oracle database for this test, so I will use an HSQL database.
Now, here comes the problem, my app is using the default producer for classes into WEB-INF/lib/*.jar files and my alternative producer for classes inside WEB-INF/classes
Is this the normal behaviour of weld injection?
There is a sample eclipse project attached, the test page is http://localhost:8080/foo-war/faces/index.xhtml
foo-jar artifact
foo-jar managed bean
{code}@Named("foo")
public class FooBean {
@Inject
private Logger logger;
public String getLoggerName() {
return logger.getName();
}
}{code}
foo-war classe code
A managed bean inside war's classes
{code}@Named("bar")
public class BarBean {
@Inject
private Logger logger;
public String getLoggerName() {
return logger.getName();
}
}{code}
My Stereotype
{code}@Stereotype
@Alternative
@Documented
@Target({ TYPE, METHOD, FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Bar {
}{code}
My producers, both at the same class, inside war's classes
{code}
public class FooResources {
// Defautl logger producer
@Produces
public Logger getFooLogger(final InjectionPoint ip) {
String category = ip.getMember().getDeclaringClass().getName();
Logger lg = Logger.getLogger(category);
lg.info("Returning a DEFAULT produced logger");
return lg;
}
// Alternative producer
@Produces
@Bar
public Logger getBarLooger(final InjectionPoint ip) {
String category = ip.getMember().getDeclaringClass().getName();
Logger lg = Logger.getLogger(category);
lg.info("Returning an ALTERNATIVE produced logger");
return lg;
}
}{code}
-
foo-bar-project.zip 19.6 KB