У меня есть эта специфицированная c модель при возврате из бросков метода rest "(Причина: отсутствует заголовок CORS 'Access-Control-Allow-Origin')." когда получил. Но когда я попытался вернуть другую модель, она успешно получена. Я уже положил @CrossOrigin
в свой контроллер.
Вот моя модель / класс
@Entity
@Table(name = "tbl_project_config")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "projectConfig")
public class ProjectConfg implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "projId")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer dbServerId;
@Column(name = "dept")
private Integer dept;
@Column(name = "name")
private String name;
@Column(name = "display_name")
private String displayName;
@Column(name = "description")
private String description;
@Column(name = "path")
private String pth;
@Column(name = "username")
private String usename;
@Column(name = "password")
private String password;
@Column(name = "application")
private Integer application;
@Column(name = "type")
private String Type;
@Column(name = "alive")
private int alive;
@OneToMany(targetEntity =ProjectHealth.class, fetch = FetchType.LAZY)
@JoinColumn(name = "projId", updatable = false)
private Set<ProjectHealth> projectHealthSet;
public ProjectConfg() {}
//getters setters
Контроллер
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600 )
@Controller
@RequestMapping(value = { "/Config/Project" }, produces = { "application/json" })
public class ProjectConfgController {
@Autowired
ProjectService projectService;
@GetMapping(path="/{type}")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody List<ProjectConfg> getList(@PathVariable String type) {
List<ProjectConfg > resultList = projectService.getAll(type, 0);
return resultList;
}
Angular сервис
@Injectable()
export class ProjectService {
private url: string;
constructor(private http: HttpClient) {
this.url= AppGlobalSetup.getHttps() + 'Config/Project/';
}
public get(type: string): Observable<any> {
return this.http.get(this.url+ type);
}
и у меня есть этот перехватчик
@Injectable()
export class CustomInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!req.headers.has('Content-Type')) {
req = req.clone({ headers: req.headers.set('Content-Type', 'application/json') });
}
req = req.clone({ headers: req.headers.set('Accept', 'application/json') });
return next.handle(req);
}
}
Вся эта настройка работает в других моделях. У меня просто есть эта конкретная c модель, которая возвращает CORS
ошибку при получении. Пожалуйста, помогите мне решить проблему с CORCS.