Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Is Autowired Annotation Deprecated in Spring Boot? Everything You Need to Know

3 min readMar 17, 2025

--

📌 Is @Autowired Deprecated in Spring Boot?

🔹 What is @Autowired?

@Service
public class ProductService {

@Autowired
private ProductRepository productRepository;

public List<Product> getAllProducts() {
return productRepository.findAll();
}
}

📌 Why is @Autowired Optional in Spring Boot 3+?

✅ How Spring Automatically Injects Dependencies

🚨 Before (Using @Autowired)

@Service
public class ProductService {
private final ProductRepository productRepository;

@Autowired // Not needed in Spring Boot 3+
public ProductService(ProductRepository productRepository) {
this.productRepository = productRepository;
}
}

✅ After (Best Practice)

@Service
public class ProductService…

--

--

Responses (1)