MyToy No.1: RMI

假设有n个银行,每个银行有m个ATM,每台ATM都可以withdraw自己银行的钱(废话),也可以withdraw别的银行的钱,for example,工商银行的机器也可以插交通银行的卡。总之有一个叫CCH的地方(central......house,想不起来了:)来处理这种类型的提款。另外,ATM还有deposit的功能(真先进,两机一体化),那么处理别的银行的存款时,CCH也要负责处理。当然,ATM也可以仅仅查账,看看account里还剩多少钱。一般来说,account不能为负数(不要考虑小数点之类的问题,处理整数就ok了)。CCH里每个银行对应一个银行账户,记录每个银行一共有多少存款(即这个银行所有accounts的balance总和),每当有transaction的时候要同步更新。(纯粹给人添麻烦,这种信息实际怎么会公布给银行之外的人)。不用保持高事务性,即用不着考虑类似transaction进行到一半时,目标银行或者CCH的服务器突然挂掉了这类情况。所有的account记录用简单的文件操作就ok了。

exception情况,如果request的目标银行的服务器not available怎么办?通常对withdrawal都是拒绝操作,(举例来说,你用交行的卡到工行的机器上去拿钱,交行的服务器发现工行的服务器连不上,当然就不能给你提款了,万一你丫的乘机疯狂透支怎么办,到时候工行赖帐不承认,交行非吐血不可)。但是,存款操作是可以接受的,因为对银行来说,这样的操作没有什么风险性,CCH要记录这类操作,当银行的服务器online的时候进行同步更新。(还是前面的例子,要是account是不存在的怎么办?还是那句话,对银行来说,风险是很低的)。显然,query在目标银行not available的时候是肯定reject掉的。

银行(BankI.java)提供的接口很简单:2套共6个,分别操作本行的存,取,查和远程的存取查(这里的"远程"是指对别家银行的操作)。

CCH(CCHI.java)要达到的功能:更新银行的account。帮银行transfer必要的操作,(即远程的操作),CCH要管routing。当目标银行不在线时要帮忙记录未完成的操作,当目标银行上线时提醒其更新account。(通常是远程操作,因为系统结构为ATM->BANK->CCH->REMOTE BANK。站在CCH的角度上,它要做的就是routing transaction和进行必要的update)。向银行提供接口,当银行上线时要求CCH提供未完成操作的记录来更新自己的account。

ATM只是简单的向用户收集必要的信息,然后调用相应的RMI即可,由于account不能为负,所以出错信息简单的用一系列的负数来标识。(用exception行不行,没细想,有空要try一下)

当发生远程banking操作时,本地银行把所有的信息传给CCH,CCH查看这个transaction是哪家银行的,然后把transaction传过去(实际上和TCP/IP一个道理,远程banking发生时,包含目标银行的名字,这个名字对CCH来说相当于一个Header,CCH剥掉这个Header之后再传给目标银行),站在bank的角度,这时进来的request,无论是从CCH来的还是从ATM来的,都是一样的,没有什么区别。

在CCH里有一个Map(bankname,Map(accno,amount))容器,用来记录未完成的操作,当银行上线时,先在容器里查询自己的名字,如果找到了,就说明有未完成操作需要同步更新,把相应的Map(accno,amount)拿出来逐个更新即可。

大致上整个project就是这样的了,具体查代码吧。

//ATM.java

import java.io.*;
import java.rmi.*;
import java.util.*;

public class ATM {
    String bankname;

    String accno;

    List banklist;

    public ATM() {
        bankname = new String();
        accno = new String();
        banklist = new Vector();
        banklist.add("CommonWealth");
        banklist.add("HSBC");
    }

    public static void main(String[] args) throws Exception {
        ATM myatm = new ATM();
        String str = new String();

        // stream from stdin
        BufferedReader sin = new BufferedReader(
                new InputStreamReader(System.in));

        System.out.println(myatm.banklist);
        System.out.print("Enter your Bank name(CommonWealth is default): ");
        myatm.bankname = sin.readLine();
        if (myatm.bankname.equals(""))
            myatm.bankname = (String) myatm.banklist.get(0);
        //System.out.println(myatm.bankname);

        // check if the bank name is valid
        boolean found = false;
        Iterator myit = myatm.banklist.iterator();
        while (myit.hasNext()) {
            if (myatm.bankname.equals(myit.next())) {
                found = true;
                break;
            }
        }
        if (!found) {
            System.out.println("Bank is not exist! check again!");
            System.exit(0);
        }

        // get account number:
        // a flaw here: doesnt check the validity of account
        // until transaction happens.
        System.out.print("Enter your account number: ");
        myatm.accno = sin.readLine();

        // connnect to bank server
        BankI mytransaction = (BankI) Naming.lookup("CommonWealth");
        while (true) {
            System.out.println("Welcome!/r/n" + "Press d: deposit/r/n"
                    + "Press w: withdrawal/r/n" + "Press q: query/r/n"
                    + "Press any other key to exit");

            // get transaction type
            str = sin.readLine();
            System.out.println("Please wait...");
            if (str.equals("d")) {
                // get money
                System.out.println("Input the amount of money please: ");
                int amount = Integer.decode(sin.readLine()).intValue();

                // decide which kind of RMI to be called.
                if (myatm.bankname.equals("CommonWealth"))
                    amount = mytransaction.deposit(myatm.accno, amount);
                else
                    amount = mytransaction.deposit(myatm.accno, amount,
                            myatm.bankname);

                // check the return value.
                if (amount == -999) {
                    System.out.println("account not exist!");
                    break;
                } else if (amount == -996) {
                    System.out.println("Your transaction has finished./r/n"
                            + myatm.bankname + " is not available now, you can"
                            + " deposit only.");
                    continue;
                } else if (amount == -995) {
                    System.out.println("CCH is not available now, "
                            + "you cannot do any remote transactions. "
                            + "Try later!");
                    break;
                }
                System.out
                        .println("==== Your new balance: " + amount + " ====");
            } else if (str.equals("w")) {
                System.out.println("Input the amount of money please: ");
                int amount = Integer.decode(sin.readLine()).intValue();

                // decide which kind of RMI to be called.
                if (myatm.bankname.equals("CommonWealth"))
                    amount = mytransaction.withdrawal(myatm.accno, amount);
                else
                    amount = mytransaction.withdrawal(myatm.accno, amount,
                            myatm.bankname);

                if (amount == -999) {
                    System.out.println("account not exist!");
                    break;
                } else if (amount == -998) {
                    System.out.println("insufficient funds!");
                    continue;
                } else if (amount == -997) {
                    System.out.println(myatm.bankname
                            + " is not available now! Try Later please.");
                    break;
                } else if (amount == -995) {
                    System.out.println("CCH is not available now, "
                            + "you cannot do any remote transactions. "
                            + "Try later!");
                    break;
                }
                System.out
                        .println("==== Your new balance: " + amount + " ====");
            } else if (str.equals("q")) {
                int amount;

                // decide which kind of RMI to be called.
                if (myatm.bankname.equals("CommonWealth"))
                    amount = mytransaction.query(myatm.accno);
                else
                    amount = mytransaction.query(myatm.accno, myatm.bankname);

                if (amount == -999) {
                    System.out.println("account not exist!");
                    break;
                } else if (amount == -997) {
                    System.out.println(myatm.bankname
                            + " is not available now! Try Later please.");
                    break;
                } else if (amount == -995) {
                    System.out.println("CCH is not available now, "
                            + "you cannot do any remote transactions. "
                            + "Try later!");
                    break;
                }
                System.out.println("==== Your balance: " + amount + " ====");
            } else
                break;
        }// while loop
    }
}

//BankI.java

// Bank system supplies:
// 1. two sets of RMI to ATM, one for its own banking, one for remote
//    banking.~Done.
// 2. accepting connection from CCH, which should pretend handling the
//    incoming transaction as the one from a ordinary ATM.~Done.
// 3. if CCH was down, local banking should be still working. in this
//    case, bank server should have a log system to record the change
//    of whole amount that will be used to update the bankbook in CCH
//    when it next logs on.~Done.
// here, assuming the ATM belongs to CW (Commonwealth).~Done.

import java.net.MalformedURLException;
import java.rmi.*;

public interface BankI extends Remote {

    // local banking:
    int withdrawal(String accno, int amount) throws RemoteException;

    int deposit(String accno, int amount) throws RemoteException;

    int query(String accno) throws RemoteException;

    // remote banking with an additional "bankname":
    int withdrawal(String accno, int amount, String bankname)
            throws MalformedURLException, RemoteException;

    int deposit(String accno, int amount, String bankname)
            throws MalformedURLException, RemoteException;

    int query(String accno, String bankname) throws MalformedURLException,
            RemoteException;

}///:~

// Bank.java

import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
import java.io.*;

public class Bank extends UnicastRemoteObject implements BankI {

    static String datafile;

    // this variable is to log the fund of bankbook when CCH is down.
    static int pending = 0;

    static Map acc = Collections.synchronizedMap(new HashMap());

    //two things to be done in the constructor:
    //1. read acc information into Map acc.~Done
    //2. check CCH if there are any transactions unfinished.~Done.
    public Bank(String bankname) throws MalformedURLException, RemoteException {
        try {
            datafile = bankname + "accinfo.txt";
            //open data file, read everything into a Map object
            BufferedReader readacc = new BufferedReader(
                    new FileReader(datafile));
            String tmpacc;
            while ((tmpacc = readacc.readLine()) != null) {
                acc.put(tmpacc, new Integer(readacc.readLine()));
            }
            readacc.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        try {
            CCHI mycch = (CCHI) Naming.lookup("CCHserver");
            Map mymsg = mycch.check(bankname);
            if (mymsg == null)
                System.out.println("No pending transaction.");
            else {
                System.out.print("handling the pending transactions...");
                Iterator myit1 = mymsg.keySet().iterator();
                Iterator myit2 = mymsg.keySet().iterator();
                Iterator myit3 = mymsg.keySet().iterator();
                while (myit1.hasNext()) {
                    acc.put(myit1.next(), new Integer(((Integer) acc.get(myit2
                    //======^key=============================================
                            .next())).intValue()
                    //=======^original value=================================
                            + ((Integer) mymsg.get(myit3.next())).intValue()));
                    //===================^pending value======================
                }

                // write back to the file
                synchronizeDatafile(acc);
                System.out.println("finished.");
            }

        } catch (NotBoundException e) {
            // if CCH is not available, just ignore this step;
            System.out.println("CCH doesn't work.");
        }
    }

    // ========================= local banking =============================
    // return -999 means that the account is not exist.
    // return -998 means that the amount is too large.
    public int withdrawal(String accno, int amount) throws RemoteException {
        if (!acc.containsKey(accno))
            return -999;
        if (((Integer) acc.get(accno)).intValue() < amount)
            return -998;
        else {
            // update Map acc.
            acc.put(accno, new Integer(((Integer) acc.get(accno)).intValue()
                    - amount));

            // update bankbook in CCH
            try {
                CCHI myupdate = (CCHI) Naming.lookup("CCHserver");
                myupdate.update("CommonWealth", pending - amount);
                pending = 0;
            } catch (NotBoundException e) {
                pending += -amount;
            } catch (Exception e) {
                System.err.println(e);
            }

            // write back to the file
            synchronizeDatafile(acc);

            return ((Integer) acc.get(accno)).intValue();
        }
    }

    public int deposit(String accno, int amount) throws RemoteException {
        if (!acc.containsKey(accno))
            return -999;
        else {
            // update Map acc.
            acc.put(accno, new Integer(((Integer) acc.get(accno)).intValue()
                    + amount));

            // update bankbook in CCH
            try {
                CCHI myupdate = (CCHI) Naming.lookup("CCHserver");
                myupdate.update("CommonWealth", pending + amount);
                pending = 0;
            } catch (NotBoundException e) {
                pending += amount;
            } catch (Exception e) {
                System.err.println(e);
            }

            // write back to the file
            synchronizeDatafile(acc);

            return ((Integer) acc.get(accno)).intValue();
        }
    }

    public int query(String accno) throws RemoteException {
        if (!acc.containsKey(accno))
            return -999;
        else
            return ((Integer) acc.get(accno)).intValue();
    }

    // ========================= remote banking ============================
    // return -999 means that the account is not exist.
    // return -998 means that the amount is too large.
    // return -997 means that the target bank is not available.
    // return -996 means that the transaction is remote deposit.
    // return -995 means that the CCH is not working.
    public int withdrawal(String accno, int amount, String bankname)
            throws MalformedURLException, RemoteException {
        CCHI mywithdrawal;
        int tmp;
        try {
            mywithdrawal = (CCHI) Naming.lookup("CCHserver");
            tmp = mywithdrawal.withdrawal(bankname, accno, amount);
        } catch (NotBoundException e) {
            return -995;
        }

        if (tmp != -999 && tmp != -998 && tmp != -997)
            mywithdrawal.update("CommonWealth", bankname, -amount);
        return tmp;
    }

    public int deposit(String accno, int amount, String bankname)
            throws MalformedURLException, RemoteException {
        CCHI mydeposit;
        int tmp;
        try {
            mydeposit = (CCHI) Naming.lookup("CCHserver");
            tmp = mydeposit.deposit(bankname, accno, amount);
        } catch (NotBoundException e) {
            return -995;
        }
        if (tmp == -996) {
            mydeposit.update(bankname, amount);
            return -996;
        }
        if (tmp != -999)
            mydeposit.update("CommonWealth", bankname, amount);
        return tmp;
    }

    public int query(String accno, String bankname)
            throws MalformedURLException, RemoteException {
        CCHI myquery;
        try {
            myquery = (CCHI) Naming.lookup("CCHserver");
        } catch (NotBoundException e) {
            return -995;
        }
        return myquery.query(bankname, accno);
    }

    // ========================= update data file ==========================
    private void synchronizeDatafile(Map acc) {
        try {
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(
                    datafile)));
            synchronized (acc) {
                Iterator iMap = acc.keySet().iterator();
                Iterator iMapprev = acc.keySet().iterator();
                while (iMap.hasNext()) {
                    pw.println(iMap.next());//key
                    pw.println(acc.get(iMapprev.next()));//value
                }
            }
            pw.close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    // ========================= main() ====================================
    public static void main(String[] args) throws Exception {

        if (args.length < 1) {
            Bank mybank = new Bank("CommonWealth");
            Naming.rebind("CommonWealth", mybank);
            System.out.println("CommonWealth Bank ready to go");
        } else {
            Bank mybank = new Bank(args[0]);
            Naming.rebind(args[0], mybank);
            System.out.println(args[0] + " Bank ready to go");
        }
        // stream from stdin
        BufferedReader sin = new BufferedReader(
                new InputStreamReader(System.in));
        System.out.println("Type /"exit/" to shutdown the server properly.");
        // expecting "exit"
        while (!sin.readLine().equals("exit"))
            ;
        System.out.print("Exiting...");
        if (args.length < 1)
            Naming.unbind("CommonWealth");
        else
            Naming.unbind(args[0]);
        System.exit(0);
    }
}

// CCHI.java

// Central Clearing House(CCH)'s job:
// 1. maintaining account of bank which is amount of the whole funds in
//    this bank. in practice,
//     i. when local banking occurs, bank system will make request
//        through RMI to update this account of bank.~Done
//    ii. when remote banking occurs, CCH will update both bank accounts
//        involved.~Done.
// 2. routing transactions between banks. when remote banking occurs,
//    CCH will call the RMI methods which belongs to the target bank server.
//    in this case, CCH itself shoudl supply a set of RMI methods to be
//    called by the bank making request.~Done.
// 3. maintaining a log system to record unfinished deposit transaction when
//    the target bank is not available.~Done.

import java.net.*;
import java.rmi.*;
import java.util.*;

public interface CCHI extends Remote {
    // 1.i
    void update(String bankacc, int fund) throws RemoteException;

    // 1.ii
    void update(String srcbank, String dstbank, int fund)
            throws RemoteException;

    // 2.
    int withdrawal(String bankname, String accno, int amount)
            throws MalformedURLException, RemoteException;

    int deposit(String bankname, String accno, int amount)
            throws MalformedURLException, RemoteException;

    int query(String bankname, String accno) throws MalformedURLException,
            RemoteException;

    // 3.
    Map check(String bankname) throws RemoteException;
}

// CCH.java

import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
import java.io.*;

public class CCH extends UnicastRemoteObject implements CCHI {

    Map book = new HashMap();

    Map bankmsg = new HashMap();

    String datafile = "bankbook.txt";

    public static void main(String[] args) throws Exception {
        CCH mycch = new CCH();

        if (args.length < 1) {
            Naming.rebind("CCHserver", mycch);
            System.out.println("CCHserver ready to go");
        } else {
            Naming.rebind(args[0], mycch);
            System.out.println(args[0] + " ready to go");
        }

        // stream from stdin
        BufferedReader sin = new BufferedReader(
                new InputStreamReader(System.in));
        System.out.println("Type /"exit/" to shutdown the server properly.");
        // expecting "exit"
        while (!sin.readLine().equals("exit"))
            ;
        System.out.print("Exiting...");
        if (args.length < 1)
            Naming.unbind("CCHserver");
        else
            Naming.unbind(args[0]);
        System.exit(0);
    }

    // similar to the bank server constructor:
    // read bank information into Map acc.~Done
    public CCH() throws RemoteException {
        try {
            //open data file, read everything into a Map object
            BufferedReader readacc = new BufferedReader(
                    new FileReader(datafile));
            String tmpacc;
            while ((tmpacc = readacc.readLine()) != null) {
                book.put(tmpacc, new Integer(readacc.readLine()));
            }
            readacc.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public int deposit(String bankname, String accno, int amount)
            throws MalformedURLException, RemoteException {
        BankI mydeposit;
        try {
            mydeposit = (BankI) Naming.lookup(bankname);
        } catch (NotBoundException e) {
            // Map(bankname, Map(accno,amount))
            System.err.println(bankname
                    + " doesn't work. I'll handle it.from CCH.deposit");
            if (!bankmsg.containsKey(bankname)) {
                Map msg = new HashMap();
                msg.put(accno, new Integer(amount));
                bankmsg.put(bankname, msg);
            } else {
                ((HashMap) bankmsg.get(bankname)).put(accno,
                        new Integer(amount));
            }
            System.err.println("I'm returning -996. from CCH.deposit");
            return -996;
        }
        return mydeposit.deposit(accno, amount);
    }

    // return -997 means that the target bank is not available.
    public int query(String bankname, String accno)
            throws MalformedURLException, RemoteException {
        BankI myquery;
        try {
            myquery = (BankI) Naming.lookup(bankname);
        } catch (NotBoundException e) {
            System.err.println("I'm returning -997. from CCH.query");
            return -997;
        }
        return myquery.query(accno);
    }

    public void update(String bankacc, int fund) throws RemoteException {
        book.put(bankacc, new Integer(((Integer) book.get(bankacc)).intValue()
                + fund));

        // write back to the file
        try {
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(
                    datafile)));
            Iterator iMap = book.keySet().iterator();
            Iterator iMapprev = book.keySet().iterator();
            while (iMap.hasNext()) {
                pw.println(iMap.next());//key
                pw.println(book.get(iMapprev.next()));//value
            }
            pw.close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    public void update(String srcbank, String dstbank, int fund)
            throws RemoteException {
        update(srcbank, -fund);
        update(dstbank, fund);
    }

    // return -997 means that the target bank is not available.
    public int withdrawal(String bankname, String accno, int amount)
            throws MalformedURLException, RemoteException {
        BankI mywithdrawal;
        try {
            mywithdrawal = (BankI) Naming.lookup(bankname);
        } catch (NotBoundException e) {
            System.err.println("I'm returning -997. from CCH.withdrawal");
            return -997;
        }
        return mywithdrawal.withdrawal(accno, amount);
    }

    public Map check(String bankname) throws RemoteException {
        return (Map) bankmsg.remove(bankname);
    }
}

// HSBCaccinfo.txt

006
1000
005
1000
007
1000

// CommonWealthaccinfo.txt

006
1000
005
1000
007
1000

// bankbook.txt

CommonWealth
3000
HSBC
3000

// Readme.txt

There are five source files in the assignment. files with suffix 'I' means
that they are interfaces and the corresponding files are implementations.

1. Compile them following steps below.

javac CCHI.java
javac CCH.java
javac BankI.java
javac Bank.java
javac ATM.java

2. Create stubs and skeletons.

rmic CCH
rmic Bank

3. Then set up the registry.

under 32-bit Windows you say:

start rmiregistry

on unix, the command is:

rmiregistry &

4. Start.

java CCH
java Bank
(and 'java Bank HSBC' to start a remote bank)
java ATM

5. Here is some guidelines.

a) Don't run same bank server or CCH server twice. Otherwise,
   the previous one will be replaced by the new server since
   they use bank name to bind to rmiregistry.
 
b) ATM is assumed as CommonWealth's property. That is, When ATM
   prompts you to input the Bank name, you can just ENTER and don't
   need to input anything when you're trying to connect CommonWealth.
   And you cannot log on to HSBC to do local banking.

c) Basically, System won't accept negative balance, so you cannot
   withdraw money more than you have in the account.

d) Only two banks(Commonwealth & HSBC) are supported in this System now.

e) Both Commonwealth and HSBC have three accounts: 005,006,007.
   And they all have 1000 balance intially. So in CCH's bankbook,
   the intial balance of the two banks is 3000, respectively.

这个blog不能上传附件的么,帖代码多恶心

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
idea报错org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/platform]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1740) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1427) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) at sun.rmi.transport.Transport$2.run(Transport.java:202) at sun.rmi.transport.Transport$2.run(Transport.java:199) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:198) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:567) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(TCPTransport.java:619) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:684) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:681) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:681) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoSuchFieldError: IS_SECURITY_ENABLED 如何解决
07-14
这个错误是由于在启动 Tomcat 时发生了异常。具体的错误信息是: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/platform]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 根本原因是 java.lang.NoSuchFieldError: IS_SECURITY_ENABLED,这意味着在调用 org.apache.tomcat.util.descriptor.tld.TldParser.parse 方法时发生了 NoSuchFieldError 异常。这个异常可能是由于版本不兼容导致的。 为了解决这个问题,你可以尝试以下几个步骤: 1. 确认你正在使用的 Tomcat 版本与你的项目兼容。检查你的项目是否符合 Tomcat 版本的要求。 2. 检查你的项目中是否存在其他与 Tomcat 版本不兼容的类库。如果有,尝试更新或删除这些类库。 3. 清理你的项目并重新编译。可以尝试删除生成的编译输出和临时文件,然后重新构建项目。 4. 检查你的项目配置文件中是否存在与 Tomcat 相关的配置错误。确保所有配置项都正确设置。 5. 尝试在启动 Tomcat 时指定正确的 Java 版本。检查你的 Tomcat 配置文件中的 JAVA_HOME 或者 JRE_HOME 是否正确设置,并且与你的项目要求的 Java 版本一致。 如果以上步骤都没有解决问题,你可以尝试升级你的 Tomcat 版本,或者尝试使用其他容器(如 Jetty)来运行你的项目。 希望这些信息对你有帮助!如果你有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值