This question already has an answer here:
- Why is my Spring @Autowired field null? 15 answers
xml configuration -
<bean id="DS" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="${DB.DRIVERCLASS}" />
<property name="url" value="${TABLEMAINT.URL}" />
<property name="username" value="${TABLEMAINT.USER}" />
<property name="password" value="${TABLEMAINT.PASSWORD}" />
</bean>
@Component
class AbcDAO{
@Autowired
private DriverManagerDataSource DS;
public void getConnection(){
System.out.println("DS - "+DS..getConnection());
}
}
datasource DS.getConnection getting null pointer exception.
Autowiring not working.
Is there any solution?
ABC is not managed by spring.
For @Autowired annotation to work you have to annotate that class with either of the following:
or define it in the XML configuration