@Configuration
public class JerseyConfig {
@Bean
public ServletRegistrationBean jerseyServlet(){
//设置服务的请求路径
ServletRegistrationBean bean = new ServletRegistrationBean(new ServletContainer(),"/rest/*");
//(Jersey servlet容器配置属性,前面配置的扫描包的类);
bean.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerserResourceRegistConfig.class.getName());
return bean;
}
}
上面配置代码 等同于下面代码中的 @ApplicationPath("/rest")
@Component
@ApplicationPath("/rest")
public class JerserResourceRegistConfig extends ResourceConfig{
public JerserResourceRegistConfig(){
//注册请求的上下文文件
//register(RequestContextFilter.class);
//注册类方式 register(WSSayHellokitty.class);
//包扫描
packages("com.example.ws");
}
}