I use weld as CDI container. Besides I use osgi (felix). So it's javase + felix+weld+pax. I have the following beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"
bean-discovery-mode="annotated">
</beans>
And I have two classes:
@ApplicationScoped
public class A {
@Inject
private B b;
public void postCreate(@Observes ContainerInitialized event, BundleContext ctx) {
b.test();
}
}
And class B
public class B{
public void test(){
System.out.println("test is here");
}
}
As you see class B doesn't have any @scopes or @dependent annotations. However when I start application object of class B is injected to object A and method test is invoked. Why? As I understand it mustn't be injected.
EDIT 1
I tried to use 1.1 version:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated" version="1.1">
</beans>
but it didn't help.
I wrote about this to weld mailing list and this is what Jozef Hartinger (one of the main weld developers) wrote
It seems that Pax CDI only implements explicit bean archives so far. I filed an issue at https://ops4j1.jira.com/browse/PAXCDI-186 You'll need to mark classes/packages you do not want discovered with @Vetoed or use an exclude filter http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#exclude_filters