-4

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?

yuva ツ
  • 3,707
  • 9
  • 50
  • 78

1 Answers1

1

ABC is not managed by spring.

For @Autowired annotation to work you have to annotate that class with either of the following:

@Component
@Service
@Controller
@Repository

or define it in the XML configuration

Janar
  • 2,623
  • 1
  • 22
  • 32