嵌套异常是javax.comm中的java.lang.NoClassDefFoundError,在部署WAR时使用Mrping MVC?

时间:2018-07-03 12:21:19

标签: spring-mvc tomcat serial-port javax.comm

正在尝试通过Spirng MVC中实现的javax.comm(WINDOWS 32)读取COM端口。是的,如果我将WAR部署在引发错误的Tomcat上,那么我就从事开发工作。

我的错误日志:

    org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: void org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration.setConfigurers(java.util.Collection); nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.gvveg.sales.SalesController] for bean with name 'salesController' defined in file [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\gvveg\WEB-INF\classes\com\gvveg\sales\SalesController.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.gvveg.sales.SalesController] for bean with name 'salesController' defined in file [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\gvveg\WEB-INF\classes\com\gvveg\sales\SalesController.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: void org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration.setConfigurers(java.util.Collection); nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.gvveg.sales.SalesController] for bean with name 'salesController' defined in file [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\gvveg\WEB-INF\classes\com\gvveg\sales\SalesController.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener

这是我的RequestMapping

@RequestMapping(value = "refreshWeight", method = RequestMethod.GET)
    public ResponseEntity<String> refreshWeight(){
        portList = CommPortIdentifier.getPortIdentifiers();

        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                 if (portId.getName().equals("COM7")) {
                     SimpleRead();
                }
            }
        }

        return new ResponseEntity<String> ( WEIGHT.trim(), HttpStatus.OK);
    }

这是我的“简单阅读”方法:

public void SimpleRead() {
        try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {System.out.println(e);}
        try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {System.out.println(e);}
    try {
            serialPort.addEventListener(this);
    } catch (TooManyListenersException e) {System.out.println(e);}
        serialPort.notifyOnDataAvailable(true);
        try {
            serialPort.setSerialPortParams(9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {System.out.println(e);}
        serialPort.close();
    }

最后,是seralEvent方法

public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
        break;
    case SerialPortEvent.DATA_AVAILABLE:
        byte[] readBuffer = new byte[20];

        try {
            while (inputStream.available() > 0) {
                int numBytes = inputStream.read(readBuffer);
            }
            System.out.println(new String(readBuffer));
            WEIGHT = new String(readBuffer);
        } catch (IOException e) {System.out.println(e);}
        break;
    }   
}

1 个答案:

答案 0 :(得分:0)

java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener

https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html

  

搜索的类定义在当前执行时存在   类已编译,但无法再找到其定义。

您的Tomcat环境或WAR文件缺少该类。