gpt4 book ai didi

spring-mvc - 嵌套异常是在部署 WAR 时使用 Srping MVC 的 javax.comm 中的 java.lang.NoClassDefFoundError?

转载 作者:行者123 更新时间:2023-11-28 23:15:04 29 4
gpt4 key购买 nike

我正在尝试通过在 Spirng MVC 中实现的 javax.comm (WINDOWS 32) 读取 COM 端口。是的,我从事开发工作,如果我在 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 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(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;
}
}

最佳答案

java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener

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

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

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

关于spring-mvc - 嵌套异常是在部署 WAR 时使用 Srping MVC 的 javax.comm 中的 java.lang.NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51154532/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com