Software⏱️ 2 min read📅 2026-05-31

How to Fix: CORS with spring-boot and angularjs not working

CORS issue with Spring Boot and AngularJS not working due to security restrictions.

Quick Answer: Enable CORS in the Spring Boot application by adding @CrossOrigin(origins = "*")

To fix the CORS issue with Spring Boot and AngularJS, you need to configure your Spring Boot application to allow requests from the AngularJS application's origin.

🛑 Root Causes of the Error

  • The main issue here is that Spring Security's default configuration blocks requests from the AngularJS application due to CORS policy violations.

🛠️ Step-by-Step Verified Fixes

Method 1: Configure CORS in Spring Boot

  1. Step 1: Add the following configuration to your Spring Boot application's configuration file (e.g., application.properties):
spring:
security:
configurerspring-security-cors-configurer

Method 2: Configure CORS in Spring Security

  1. Step 1: Add the following configuration to your Spring Boot application's WebSecurityConfigurerAdapter:
@Configuration@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.cors().and(); }}

🎯 Final Words

By implementing these steps, you should be able to access the REST endpoints from your AngularJS application.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions