Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.transaction.NoTransactionExcep tion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.transaction.NoTransactionExcep tion

    PHP Code:
                 ApplicationContext context = new ClassPathXmlApplicationContext(
                        
    "com/spring/jdbc/test/ApplicationContext.xml");

                
    DataCon bean1 = (DataConcontext.getBean("datacon");
                
    DataSource ds bean1.dbcon();
                
    jt = new JdbcTemplate(ds);
                
                
    TestJdbcTemplate sp = new TestJdbcTemplate();
                
    sp.execute();
    }
    public 
    Map execute() {
            
    HashMap inpar = new HashMap();
            
    inpar.put("name""Kasim");
            
    inpar.put("id""1122");
            return 
    execute(inpar);
        } 
    and my xml file is:

    PHP Code:
    <beans
      <
    bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      </
    bean>
      <
    bean id="dataSource" 
          
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        <
    property name="driverClassName"
           <
    value>oracle.jdbc.driver.OracleDriver</value
        </
    property
        <
    property name="url"
           <
    value>jdbc:oracle:thin:@10.237.204.86:1521:CDOI1</value
        </
    property
        <
    property name="username"
           <
    value>CDO</value
        </
    property
        <
    property name="password"
           <
    value>CDO</value
        </
    property
      </
    bean
      <
    bean   id="datacon"  class="com.spring.jdbc.test.DataConImpl"
        <
    property name="dataSource"
            <
    ref local="dataSource"/> 
        </
    property
      </
    bean
      <
    bean   id="jdbcTemplates"  class="com.spring.jdbc.test.TestJdbcTemplate"
        <
    property name="JDBCTemplate"
            <
    ref local="jdbcTemplate"/> 
        </
    property
      </
    bean
    </
    beans
    when i run this i am getting error as:
    PHP Code:
    Exception in thread "main" org.springframework.transaction.NoTransactionExceptionNo transaction aspect-managed TransactionStatus in scope
        at org
    .springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus(TransactionAspectSupport.java:106)
        
    at com.spring.jdbc.test.TestJdbcTemplate.main(TestJdbcTemplate.java:52

  • #2
    You define a TestJdbcTemplate bean inside config file, but in your test you create a new one, not letting Spring manage it.
    Also, why don't you use the data-source defined inside your config file for JdbcTemplate ?
    Can you provide more detailed stack-trace ?

    Comment


    • #3
      PHP Code:
      org.springframework.beans.factory.BeanCreationExceptionError creating bean with name 'jdbcTemplate' defined in class path resource [com/spring/jdbc/test/ApplicationContext.xml]: Invocation of init method failednested exception is java.lang.IllegalArgumentExceptionProperty 'dataSource' is required
      Caused by
      java.lang.IllegalArgumentExceptionProperty 'dataSource' is required
          at org
      .springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:134)
          
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1175)
          
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1145)
          
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
          
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
          
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
          
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
          
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
          
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:279)
          
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:360)
          
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
          
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
          
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
          
      at com.spring.jdbc.test.TestJdbcTemplate.main(TestJdbcTemplate.java:39)
      Exception in thread "main" org.springframework.transaction.NoTransactionExceptionNo transaction aspect-managed TransactionStatus in scope
          at org
      .springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus(TransactionAspectSupport.java:106)
          
      at com.spring.jdbc.test.TestJdbcTemplate.main(TestJdbcTemplate.java:53
      i have removed the calling methods as you said still i am getting same error.
      Last edited by kasim; Jul 4th, 2007, 01:39 AM.

      Comment


      • #4
        JdbcTemplate needs a data-source to be provided:
        Code:
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource">
                <ref local="dataSource"/>
            </property> 
        </bean>
        http://static.springframework.org/sp...c-JdbcTemplate

        Comment

        Working...
        X