我正在使用RESTful服務的項目。我有模塊作爲Web層,業務層等。我添加了基本的api圖層(使用球衣),並獲得了獲取請求的基本響應。現在我必須將它連接到業務層。我是谷歌搜索,但我不知道如何實施每個解決方案,我的項目。從業務層的澤西島的基本依賴注入
這是我的行程資源類:
@Path("trip")
public class TripResource {
@Context
private UriInfo context;
@Inject
private AdminService adminService;
public TripResource() {
}
@GET
@Produces("text/plain")
public List<TripDTO> getText() {
return adminService.listAllTrips();
}
}
,這我使用的添加資源類:
@javax.ws.rs.ApplicationPath("api")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(cz.infi.javatravelagency.ServiceResource.class);
resources.add(cz.infi.javatravelagency.TripResource.class);
}
}
我的pom.xml:
<name>JavaTravelAgency - Api module</name>
<dependencies>
<dependency>
<groupId>cz.infi</groupId>
<artifactId>javatravelagency-business</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Java language version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
<!-- Servlet 3.0 without web.xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
我試着按照answer in this link。我只是補充道:
public class MyApplicationBinder extends AbstractBinder {
@Override
protected void configure() {
bind(AdminServiceImpl.class).to(AdminService.class);
}
}
現在我被卡住了。
如何將此活頁夾添加到我的配置類? 沒有使用任何其他技術,最簡單的實現是什麼?