When I access a bean from spring bean configuration file using BeanFactory like this:
public class Person {
private String id,address;
@Autowired
pri
When using Spring with an XML context, using annotations is not activated by default. This means @Autowired
, @Transactional
, @PostConstruct
and any other annotation you will use will simply not be exploited.
To make Spring aware of annotations, you need to add the following line:
Thus, Spring will search for annotations in the beans it creates and process them accordingly.
This requires activating the context
namespace. At the top of your context, make sure you have all context
related links and arguments1:
You do not need
in your case. This would be useful if you used full-annotation context (e.g. classes annotated with @Component
). See the difference between
and
in this answer.
As Naman Gala suggested, you could also drop @Autowired
completely and inject all dependencies in XML. See the related answer for more details.
1 This includes the xmlns:context
attribute (xmlns = XML NameSpace) and two URLs in xsi:schemaLocation
.