Announcement Announcement Module
Collapse
No announcement yet.
Trying to get a reference to a dao interface Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    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, 08: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.

    Comment


    • #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, 02:36 PM.

      Comment

      Working...
      X