嵌套的例外是java.lang.NoClassDefFoundError在javax.comm中使用Srping MVC



我试图通过Javax.comm(WINDOWS 32(读取COM端口,该端口在Spirng MVC中实现。是的,我从事开发工作,如果我在 Tomcat 上部署 WAR 会抛出错误。

我的错误日志:

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 FilesApache Software FoundationTomcat 9.0webappsgvvegWEB-INFclassescomgvvegsalesSalesController.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 FilesApache Software FoundationTomcat 9.0webappsgvvegWEB-INFclassescomgvvegsalesSalesController.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 FilesApache Software FoundationTomcat 9.0webappsgvvegWEB-INFclassescomgvvegsalesSalesController.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener

这是我的请求映射

@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();
}

最后,seral事件方法

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;
}   
}

java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener

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

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

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

最新更新