javaspring

migrate Spring app from XML to annotations


I've inherited a Spring 3 app that uses XML files to define and wire together the beans. I know that since Spring 2 these can mostly be replaced with annotations. I would like Spring to:

What are steps I need to take to make this happen?


Solution

  • The manual has all the info you need: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-annotation-config

    The TL;DR version is that you need to add <context:annotation-config/> to your spring config and then annotate your beans with @Component and in your setter of properties annotate with @Autowired