JF *_*ier 8 java dependencies dependency-injection maven
我们公司在两件工件中创建了一个ejb.impl工件包含实现,客户端工件包含所有接口.这意味着impl工件对客户端工件具有编译依赖性.
现在,在运行时,客户端工件需要impl工件 - 否则容器无法注入所需的对象.这意味着耳朵需要包含所有客户端工件的impl工件.
这是否意味着客户端工件应该runtime依赖于impl工件?或者是否应该避免这些"循环"依赖,即使一个方向是另一个方向compile,另一个是runtime?
您无需关心客户端对实现的隐式依赖,因为服务器将对此进行管理。
EJB 容器创建一个代理,通过该代理调用实现,因此客户端永远不会直接引用它。
如果您有 EJB 的 pom,其中包含:
<groupId>com.stackoverflow</groupId>
<artifactId>Q43120825-server</artifactId>
<packaging>ejb</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Q43120825-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.2</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
EAR 文件 pom 包含:
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Q43120825-server</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
... other modules
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<version>7</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<ejbModule>
<groupId>com.stackoverflow</groupId>
<artifactId>Q43120825-server</artifactId>
<bundleFileName>Q43120825-server.jar</bundleFileName>
</ejbModule>
... other modules that might have the API jar as a dependency
</modules>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
那么这将构建一个正确的 EAR 文件,其lib目录中包含 API jar。
| 归档时间: |
|
| 查看次数: |
230 次 |
| 最近记录: |