有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

春季组织。springframework。豆。工厂BeanCreationException。。。JAVAlang.NoClassDefFoundError:com/atomikos/diagnostics/Console

我越来越

org.springframework.beans.factory.BeanCreationException....java.lang.NoClassDefFoundError: com/atomikos/diagnostics/Console

梅因。爪哇

package com.nody.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.nody.spring.global.AccountInter;

public class Main {
    public static void main(String arg[]) throws Exception
    {
    ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
    Object o=ctx.getBean("accimpl");
    AccountInter inter=(AccountInter)o;
    inter.transferMoney(101,102,2000);

    }
}

这是我的界面

会计国际。爪哇

package com.nody.spring.global;

public interface AccountInter {
    void transferMoney(int accno1,int accno2,int amount) throws Exception;

}

下面是实现类AccountImpl。爪哇

package com.nody.spring.global;


import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;

public class AccountImpl implements AccountInter {

    private JdbcTemplate jt1;
    private JdbcTemplate jt2;

    public void setJt1(JdbcTemplate jt1) {
        this.jt1 = jt1;
    }

    public void setJt2(JdbcTemplate jt2) {
        this.jt2 = jt2;
    }

    @SuppressWarnings("deprecation")
    @Override
    @Transactional(timeout=5)
    public void transferMoney(int accno1, int accno2, int amount) throws Exception
    {
    int s1=jt1.queryForInt("select bal from Account1 where acno=?",accno1);

    //Deducting amount from balance
    int s2=s1-amount;
    if(s2<500)
    {
        throw new Exception();  
    }

    int s3=jt2.queryForInt("select bal from Account2 where accno=?",accno2);
    //adding amount to account2 
    int s4=s3+amount;
    jt1.update("update Account1 set bal=? where accno=?",s2,accno1);
    jt2.update("update Account2 set bal=? where accno=?",s4,accno2);
    System.out.println("Transaction Successfull !");
    }

}

这是applicationContext。xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!--- Business bean Configuration -->
<bean id="accimpl" class="com.nody.spring.global.AccountImpl">
<property name="jt1"   ref="jt1"></property>
<property name="jt2"   ref="jt2"></property>
</bean>

<!--JdbcTemplate -->
<bean id="jt1" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource"   ref="ds1"></property>
</bean>

<bean id="jt2" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource"   ref="ds2"></property>
</bean>

<!-- -DataSource Configuration DATABASE-1  -->
<bean id="ds1"  class="com.atomikos.jdbc.AtomikosDataSourceBean"  init-method="init"   destroy-method="close">
<property name="uniqueResourceName"  value="A"></property>
<property name="xaDataSourceClassName"  value="oracle.jdbc.xa.client.OracleXADataSource"></property>
<property name="xaProperties">
<props>
<prop key="databaseName">xe</prop>
<prop key="user">scott</prop>
<prop key="password">tiger</prop>
<prop key="URL">jdbc:oracle:thin:@localhost:1521:xe</prop>
</props>
</property>
<property name="poolSize"  value="1"></property>
</bean>


<!-- DataSource Configuration DATABASE2 -->
<bean id="ds2"   class="com.atomikos.jdbc.AtomikosDataSourceBean"   init-method="init"   destroy-method="close">
<property name="uniqueResourceName"   value="B"></property>
<property name="xaDataSourceClassName"   value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"></property>
<property name="xaProperties">
<props>
<prop key="databaseName">nody</prop>
<prop key="user">root</prop>
<prop key="password"></prop>
<prop key="URL">jdbc:mysql://localhost:3306/nody</prop>
</props>
</property>
<property name="poolSize" value="1"></property>
</bean>

<bean id="atomikosTransactionManager"   class="com.atomikos.icatch.jta.UserTransactionManager"   init-method="init"   destroy-method="close">
</bean>

<bean id="txm"   class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<ref bean="atomikosTransactionManager"></ref>
</property>
</bean>
<tx:annotation-driven   transaction-manager="txm"/>
</beans>

这里是我的应用程序目录结构

aopalliance.jar
aspectjrt-1.8.5.jar
aspectj-weaver.jar
atomikos-transactions-api.jar
atomikos-transactions-jta.jar
atomikos-util-4.0.0M4.jar
commons-logging-api-1.1.1.jar
jta.jar
mysql-connector-java-5.1.6.jar
ojdbc14.jar
spring-aop-4.1.4.RELEASE.jar
spring-beans-4.1.4.RELEASE.jar
spring-context-4.1.4.RELEASE.jar
spring-context-support-4.1.4.RELEASE.jar
spring-core-4.1.4.RELEASE.jar
spring-expression-4.1.4.RELEASE.jar
spring-jdbc-4.1.4.RELEASE.jar
spring-tx-4.1.4.RELEASE.jar
transactions-3.7.0.jar
transactions-jdbc-3.7.0.jar

以下是完整的异常详细信息

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jt1' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'ds1' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds1' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/atomikos/diagnostics/Console

我真的很累,但没有得到什么发生。请帮帮我


共 (1) 个答案

  1. # 1 楼答案

    运行时在类路径上找不到类com.atomikos.diagnostics.Console

    如果使用Maven构建,请添加以下依赖项:

    <dependency>
        <groupId>com.atomikos</groupId>
        <artifactId>atomikos-util</artifactId>
        <version>3.7.1</version>
    </dependency>
    

    http://mvnrepository.com/artifact/com.atomikos/atomikos-util

    否则,从该站点下载atomikos-util.jar,并将其添加到类路径中

    编辑:3.7.1似乎是包含Console类的最后一个版本

    http://mvnrepository.com/artifact/com.atomikos/atomikos-util/3.7.1下载