我让Zuul Proxy作为网关应用程序在8080中运行,而Project Application作为微服务在8090中运行。我试图通过Rest Controller创建一个项目,但是当我尝试访问url时,面临访问被拒绝的问题并获得响应为401。
项目微服务
项目申请
@EnableGlobalMethodSecurity(securedEnabled = true)
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "packagename")
public class ProjectApplication {
public static void main(String[] args) {
SpringApplication.run(ProjectApplication.class, args);
}
}
如果我评论GlobalSecurity注释,它会完美地工作。但是没有进行权限检查。
ProjectController
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping(value = ApplicationConstant.API_PATH_PROJECT)
public class ProjectController {
private static final Logger logger = LoggerFactory.getLogger(ProjectController.class);
@Autowired
ProjectService projectService;
@Secured({ RoleConstant.ROLE_ADMIN_PROJECT})
@Transactional(rollbackFor = { Exception.class })
@RequestMapping(value = ApplicationConstant.API_PATH_CREATE, method = RequestMethod.POST)
public ResponseEntity<?> create(@ModelAttribute ProjectRequest projectRequest, HttpServletRequest request)
throws ApiException, IOException, ParseException {
....
}
}
网关/ Zuul属性
server.port=8080
eureka.client.enabled=true
eureka.client.eureka-server-port=8761
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
eureka.instance.prefer-ip-address=true
#zuul.ignored-headers=Access-Control-Allow-Credentials, Access-Control-Allow-Origin
zuul.sensitive-headers=Cookie,Set-Cookie,Authorization