Примечание : убедитесь, что вы используете ту же версию в файлах pom
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
<version>2.25.1</version>
</dependency>
web.xml (необходимо перенести)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false" version="3.1">
<servlet>
<servlet-name>accRestService</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.test.ciam.acctmgt</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.bitguiders.ciam.acct.MyAppConfig</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>accountManagementRestService</servlet-name>
<url-pattern>/acc/api/*</url-pattern>
</servlet-mapping>
</web-app>
MyAppConfig (необходимо перенести / обновить)
package org.bitguiders.acc.cfg;
import org.bitguiders.api.exceptions.GenericExceptionMapper;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
public class MyAppConfig extends ResourceConfig {
public ApplicationConfig() {
register(JacksonFeature.class);
register(GenericExceptionMapper.class);
register(new DependencyBinder());
}
}
ApplicationConfig.java isЗамена web.xml и MyAppConfig.java новым классом конфигурации на основе Java / Annotation.
package org.bitguiders.acc.cfg
import javax.ws.rs.ApplicationPath;
import org.bitguiders.acc.api.exceptions.GenericExceptionMapper;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("acc/api/*")
public class ApplicationConfig extends ResourceConfig {
public ApplicationConfig() {
packages("org.bitguiders.acc");
register(JacksonFeature.class);
register(GenericExceptionMapper.class);
register(new DependencyBinder());
}
}
HK2 Binding Общий доступ к этому классу только дляпоказать, как выполняется привязка HK2 и для чего нужен регистр (новый DependencyBinder ())
package org.bitguiders.acc.cfg;
import javax.inject.Singleton;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.process.internal.RequestScoped;
public class DependencyBinder extends AbstractBinder{
private static final String UNSECURED = "unsecured";
private static final String SECURED = "secured";
@Override
protected void configure() {
bind(AccountManagementServiceImpl.class).to(AccountManagementService.class).in(Singleton.class);
bindFactory(AccessTokenStoreFactory.class).proxy(true).proxyForSameScope(false).to(AccessTokenStore.class).in(RequestScoped.class);
bind(CASLocationServiceImpl.class).to(LocationService.class).named(CAS_LOCATION_SERVICE).in(Singleton.class);
bindAsContract(LocationServiceFactory.class).in(Singleton.class);
bindFactory(AccessTokenProviderFactory.class).to(AccessTokenProvider.class).to(new TypeLiteral<Provider<String>>(){}).in(Singleton.class);
bind(CiamScim2ClientRequireTokenImpl.class).to(CiamScim2Client.class).named(SECURED).in(Singleton.class);
bind(CiamScim2ClientImpl.class).to(CiamScim2Client.class).named(UNSECURED).in(Singleton.class);
bind(AccountManagementOptionsServiceImpl.class).to(AccountManagementOptionsService.class).named(SECURED).in(Singleton.class);
bindAsContract(OptionsApiServiceFactory.class).in(Singleton.class);
}
}