How can I Initialize getJdbcTemplate()? - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 38 of 38

Thread: How can I Initialize getJdbcTemplate()?

  1. #31
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Have you annotated your JUnit test class one way or another to tell it to load the application context that it needs to wire the beans that you plan to use for testing. I have a feeling that your job bean is probably null at this point.

    Code:
    @RunWith (SpringJUnit4ClassRunner.class)
    @ContextConfiguration (locations={"/application-context.xml"})
    assuming that you have an 'application-context.xml' in the same project, otherwise you have to use
    Code:
    classpath*:out-of-scope-context.xml
    note that these names application-context.xml and out-of-scope-context.xml need to match your contexts
    Last edited by Deliverance; October 26th, 2009 at 10:22 AM.
    ------
    If you are satisfied with the responses, add to the user's rep!

  2. #32
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    I am using JDK 1.4.x

    Code:
    @RunWith (SpringJUnit4ClassRunner.class)
    @ContextConfiguration (locations={"/application-context.xml"})
    annotation is not allowing. What I need to do with out changing JDK version?
    Thanks in advance.

  3. #33
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Ok, so in this case I guess you would have to create your own application context inside of each unit test.

    something like this

    Code:
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
    then from there, you can request things by bean id by default.

    Code:
    MyCustomBean myBean = (MyCustomBean)context.getBean("myBeanId");
    and then invoke that way.
    ------
    If you are satisfied with the responses, add to the user's rep!

  4. #34
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    CGenerationScheduledJobTestCase.java
    Code:
    public void testRunScheduledJob() {
       AbstractApplicationContext context = new    
       ClassPathXmlApplicationContext("????");
     .
     .		
    }

    WEB-INF\Integration-dao.xml
    Code:
    .
    .
    <bean id="cListDAO" class="com…..cc.business.dao.CCCListDAO">
    </bean>
    .
    .


    WEB-INF/Integration-webapp.xml
    Code:
    <beans>
    <context:property-placeholder
    		location="classpath:jdbc.properties,
    				  classpath:com/././././mail.properties" />
    
    	<import resource="/Integration-dao.xml" />
    	<import resource="/Integration-datasource.xml" />
    </beans>

    WEB-INF\web.xml
    Code:
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/Integration-webapp.xml</param-value>
    </context-param>

    Above is the xml mapping in my project.
    Here I want object of cListDAO using getBean() method.
    To achieve this what I need to give for ClassPathXmlApplicationContext(“????”)

    Thanks

  5. #35
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    So since the entry point of this web application is through servlet API context initialized, the web application context is good enough since it is importing the other contexts that you may require.

    Code:
    public void testRunScheduledJob() {
       AbstractApplicationContext context = new    
       ClassPathXmlApplicationContext("Integration-webapp.xml);
     .
     .		
    }
    That should find it that way, then you can use the getBean methods as i showed you before.
    ------
    If you are satisfied with the responses, add to the user's rep!

  6. #36
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    but "Integration-webapp.xml" is also not in classpath

    it is in WEB-INF folder. I tried but file not found exception is comming. I belive loading is happening using web.xml.

    Code:
    WEB-INF/Integration-webapp.xml
    Please help.

  7. #37
    Join Date
    Apr 2007
    Posts
    425

    Re: How can I Initialize getJdbcTemplate()?

    Quote Originally Posted by java_dev View Post
    but "Integration-webapp.xml" is also not in classpath

    it is in WEB-INF folder. I tried but file not found exception is comming. I belive loading is happening using web.xml.

    Code:
    WEB-INF/Integration-webapp.xml
    Please help.
    well the only problem here is a file lookup.

    create another context under say src/test/resources
    for unit tests which does what integration-webapp does then. This is usually the preferred way to do 'unit testing' and not 'integration testing' where you use another datasource (in memory database, etc).
    ------
    If you are satisfied with the responses, add to the user's rep!

  8. #38
    Join Date
    Sep 2009
    Posts
    24

    Re: How can I Initialize getJdbcTemplate()?

    Currently I am working on more priority work! Please give me some time to reply.

    Deliverance, i posted new request/thread on webservices. Can you please help me on this.

    Thread Link:
    ---------------
    http://www.codeguru.com/forum/showth...18#post1894318


    Thanks In advance.

Page 3 of 3 FirstFirst 123

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center