CDI and web fragments: not working without beans.xml

1.3k Views Asked by At

I have three maven projects:

  • core (packagetype=JAR) with src/main/resources/beans.xml bean-discovery-mode="annotated"
  • webfragment (packagetype=JAR) with src/main/resources/beans.xml bean-discovery-mode="annotated"
  • webproject (packagetype=WAR) with src/main/webapp/WEB-INF/beans.xml bean-discovery-mode="annotated"

I have org.jboss.weld.servlet:weld-servlet 2.2.9.Final (CDI 1.2) in my classpath and use a tomcat 7.0.55. Furthermore I use Servlet 3, Deltaspike 1.2.1, Mojarra 2.2.10.

All of my CDI beans have a bean defining annotation (see Meaning of bean discovery mode annotated in CDI 1.1)

Weld warns me about

servletWeldServlet [WARN] WELD-ENV-001004: Found both WEB-INF/beans.xml and WEB-INF/classes/META-INF/beans.xml. It's not portable to use both locations at the same time. Weld is going to use jndi:/localhost/webproject/WEB-INF/beans.xml.

but everything works fine.

So, I deleted all beans.xml because I shouldn't need them with CDI 1.2 but afterwards nothing works any longer: WELD-001408: Unsatisfied dependencies...

What did I miss? Is this a web fragment problem?

1

There are 1 best solutions below

1
On

Unsatisified dependencies at injection point [BackedAnnotatedMethod] or something similar

Shows you at which injection point the resolution failed, check if the type of the injected field is annotated.

That is:

@Inject
private SomeService injectedService;

Then CDI1.2 mandates that if no beans.xml is defined, it will only scan annotated beans.

Hence

@SessionScoped or 
{@ApplicationScoped, @Dependent, @RequestScoped, @ConversationScoped}
public class SomeService{}