-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?

5
  • Read the Java naming convention. Property names should start with lower case character so your "DS" must be "ds" Commented May 22, 2017 at 12:14
  • @pvpkiran no. it's my dao class Commented May 22, 2017 at 12:14
  • How you instanciate the class ABS? Is it a spring managed bean? Commented May 22, 2017 at 12:14
  • Yes.. I haven't copied full code here Commented May 22, 2017 at 12:15
  • Add the related code as well Commented May 22, 2017 at 12:17

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

9 Comments

which one I should use from these?
IT's not my controller or service class
@yuvaツ is it a repository? if not use '@Component'
No. Tried with component also.. not working
see code updated..
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.