Announcement Announcement Module
No announcement yet.
Trying to get a reference to a dao interface Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to get a reference to a dao interface

    I've have a web application deployed in web logic 8.1 that uses iBaits and Spring and cannot figure out how to get a reference to the dao interface called "Confirmation' from my business class without doing this in each class that needs to use the dao:

    Confirmation conf;
    ApplicationContext context = 
    		new ClassPathXmlApplicationContext(applicationContext.xml);
    	 conf = (Confirmation)context.getBean("confirmation");
    Do I need to do it this way? I was hoping I wouldn't have to write that out.

    I thought if I loaded the applicationContext with ContextLoaderServlet via web.xml I could just use setter injection to get the handle to the dao interface in my ConfirmationManager class and start calling dao methods but it is null when I try to use it so its not working.

    I'm new to Spring so any help would be appreciated. Thanks


       <bean id="confirmation" class="">
          <property name="dataSource" ref="dataSource" />
          <property name="sqlMapClient" ref="sqlMapClient" />
        <tx:advice id="txAdvice" transaction-manager="txManager">
          	<tx:method name="get*" read-only="true"/>
          	<tx:method name="*"/>
          <aop:pointcut id="confirmationOperation" expression="execution(**(..))"/>
    	  <aop:advisor advice-ref="txAdvice" pointcut-ref="confirmationOperation"/>
    	<jee:jndi-lookup id="dataSource" jndi-name="jdbc/VCSCDataSource" cache="true" />
    	<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          <property name="dataSource" ref="dataSource"/>
        <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="configLocation" value="/WEB-INF/SqlMapConfig.xml" />
            <property name="dataSource" ref="dataSource" />
    	<bean id="nativeJdbcExtractor" class="" 
    	<bean id="oracleLobHandler" class="" lazy-init="true">
    		<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
        <bean id="confirmationManager" class="">
        	<property name="conf" ref="confirmation" />

    Confirmation interface
    public interface Confirmation {
      public void archiveConfimationMessage(ConfirmationArchive archive);

    ConfirmationManager code snippet
    private Confirmation conf;
    public void setConf(Confirmation conf) {
      this.conf = conf;
    -- calling this gets a null pointer since data is null --
     public void archiveConfimationMessage(ConfirmationArchive archive) {

    Was hoping setter injection would give me a handle to conf. Not sure what im doing wrong.
    Last edited by Dave Townsend; Aug 8th, 2007, 09:36 PM.

  • #2
    found the issue. the setter injection is working properly. after initialization the class is being created again by a caller so the injected class is now null. not sure how to fix that yet.


    • #3
      Originally posted by Dave Townsend View Post
      after initialization the class is being created again by a caller so the injected class is now null. not sure how to fix that yet.
      If you add some more details that might help to solve it.
      Last edited by karldmoore; Aug 27th, 2007, 03:36 PM.