0

I'm trying to deploy a simple WAR file on wildfly 9.0.2 final. The WAR has no web.xml and no EJB's for the moment - just, via annotations, a websocket endpoint with a dependency injection in the constructor and factories to produce the dependencies. On deployment, I get the error:

java.lang.NoSuchMethodException: com.aip.textspace.infra.control.websocket.MainEndPoint.<init>

It looks like widlfly is trying to call a null constructor which does not exist. Here is the constructor for MainEndPoint:

@Inject
public MainEndPoint(SessionController control) {
    super();
    this.control = control;
}

I have another class called SessionControllerFactory which has a producer method for the injection:

@Produces
public SessionController build() {
...

In the Maven POM, I reference the CDI library:

   <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

So what did I leave out that is needed for wildfly to call the constructor with dependency injection?

BTW, based on a related response, I tried adding a null constructor to MainEndPoint. In that case the deployment succeeds but the injection never happens, and I get null pointer exceptions when accessiong this.control in MainEndPoint.

Community
  • 1
  • 1
aro_tech
  • 1,103
  • 7
  • 20

1 Answers1

1

The reason seems obvious: somehow SessionController hasn't been registered as a CDI bean.

Please make sure that in the following code:

 @Produces
 public SessionController build() {
    ...
 }

annotation @Produces states for @javax.enterprise.inject.Produces, not @javax.ws.rs.Produces accidently.

Also please make sure that SessionControllerFactory is included in your war archive and it is a managed bean class.

BTW: you didn't mention anything about your beans.xml file (which is optional in WildFly 9 and in EE 7 in general). For the test purpose, you can add such file, set its attribute bean-discovery-mode="ALL" and check what happen.

G. Demecki
  • 10,145
  • 3
  • 58
  • 58
  • 1
    I needed to make the factory classes (SessionControllerFactory and the factories needed for its contruction) @Singleton EJB's and add useless null constructors for them. Works perfectly now. No need for beans.xml, for the moment. – aro_tech Nov 03 '15 at 06:41