Вложенное исключение - это java.lang.NoClassDefFoundError в javax.comm со Srping MVC при развертывании WAR?
Пытаюсь прочитать COM-порт через javax.comm (WINDOWS 32), который реализован в Spirng MVC. Да, я работал над разработкой, если развернул 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(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 ответ
java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener
https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html
Поисковое определение класса существовало, когда выполняемый в данный момент класс был скомпилирован, но определение больше не может быть найдено.
В вашей среде Tomcat или файле WAR отсутствует этот класс.