我在服务定义接口(GateRs)上设置CORS
...
@Service
@CrossOriginResourceSharing(
allowAllOrigins = true,
allowHeaders = {
"Accept", "Accept-Charset", "Accept-Encoding", "Accept-Datetime",
"Accept-Language", "Authorization", "Content-Language", "Content-Length",
"Content-Type", "Origin", "User-Agent"},
exposeHeaders = {
"Accept", "Accept-Charset", "Accept-Encoding", "Accept-Datetime",
"Accept-Language", "Authorization", "Content-Language", "Content-Length",
"Content-Type", "Origin", "User-Agent"},
allowCredentials = true,
maxAge = 1209600 )
public interface GateRs {
@POST
@Path("/require")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@VoluntarySecure
public Res require(Req req);
...
实现与类的接口
@Component
public class Gate implements GateRs {
@Override
public Res require(Req req) {
...
将“CrossOriginResourceSharingFilter”附加到服务bean
@Bean
public CrossOriginResourceSharingFilter cors() {
return new CrossOriginResourceSharingFilter();
}
@Bean(destroyMethod = "destroy") @DependsOn(Bus.DEFAULT_BUS_ID)
public Server jaxRsServer() {
final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setServiceBean(new Gate());
factory.setProviders(Arrays.asList(jackson(), cors()));
factory.setBus(springBus());
factory.setAddress("/Gate");
return factory.create();
}
...
客户端是一个基于离子的移动应用程序,由Chrome浏览器模拟。
访问控制允许原点”标题。
飞行前(选项)
发帖失败;服务器端似乎没有在响应消息中显示“Access Control Allow Origin”头
有人有什么想法或建议吗?
谢谢