Results 1 to 3 of 3

Thread: Trying to get a reference to a dao interface

  1. #1

    Default 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:

    Code:
    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

    web.xml
    Code:
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    	</context-param>
    	
    	<servlet>
    		<servlet-name>context</servlet-name>
    		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>

    applicationContext.xml
    Code:
       <bean id="confirmation" class="com.company.booking.ConfirmationRepository">
          <property name="dataSource" ref="dataSource" />
          <property name="sqlMapClient" ref="sqlMapClient" />
        </bean>
        
        <tx:advice id="txAdvice" transaction-manager="txManager">
          <tx:attributes>
          	<tx:method name="get*" read-only="true"/>
          	<tx:method name="*"/>
          </tx:attributes>
        </tx:advice>
    	
    	<aop:config>
          <aop:pointcut id="confirmationOperation" expression="execution(* com.company.booking.Confirmation.*(..))"/>
    	  <aop:advisor advice-ref="txAdvice" pointcut-ref="confirmationOperation"/>
    	</aop:config>
    	
    	<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>
    	
        <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="configLocation" value="/WEB-INF/SqlMapConfig.xml" />
            <property name="dataSource" ref="dataSource" />
        </bean>
        
    	<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" 
    		lazy-init="true"/>
    
    	<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
    		<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
    	</bean>
        
        <bean id="confirmationManager" class="com.company.booking.ConfirmationManager">
        	<property name="conf" ref="confirmation" />
        </bean>
    </beans>

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

    ConfirmationManager code snippet
    Code:
    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) {
    	conf.archiveConfimationMessage(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 at 08:36 PM.

  2. #2

    Default

    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. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 02:36 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •