I am trying to inject a bean into my main class of the program. I have two modules under Apache Maven:
- Java Parent
- Module1
- Module2
Part of the pom file looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.screening</groupId>
<artifactId>screening</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Java Parent</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>Module1</module>
<module>Module2</module>
</modules>
</project>
Module1 pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.screening</groupId>
<artifactId>screening</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.screening</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>Module1</name>
</project>
I have a stateless and local bean in Module1:
@Stateless
@Local
public class JDBCProcessorBean implements JDBCProcessorBean {
// implemented methods
}
I inject this class in the same module:
@Startup
@Singleton
public class Runner {
@EJB
private JDBCProcessor jdbcProcessor; // this is injected at runtime
}
The JDBCProcessor is injected at runtime and I can use the methods of JDBCProcessor. The issue comes in when I inject module2 bean into the Runner class. It cannot find the class that I have. Again it has @Stateless and @Local. Even if I try to use @Remote it still cannot find it. I get
javax.NamingNotFoundException
The only issue is injecting the bean that is in a different module. How can this be fixed?