前两天发布最新版本后 今天已经开始尝试 ,发现导出失败 ,堆栈信息如下:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" com.alibaba.excel.exception.ExcelGenerateException: java.lang.NoClassDefFoundError: com/alibaba/excel/support/util/CollectionUtils
at com.alibaba.excel.write.ExcelBuilderImpl.<init>(ExcelBuilderImpl.java:42)
at com.alibaba.excel.ExcelWriter.<init>(ExcelWriter.java:39)
at com.alibaba.excel.write.builder.ExcelWriterBuilder.build(ExcelWriterBuilder.java:133)
at DemoExport.main(DemoExport.java:11)
Caused by: java.lang.NoClassDefFoundError: com/alibaba/excel/support/util/CollectionUtils
at com.alibaba.excel.util.ClassUtils.doDeclaredFields(ClassUtils.java:327)
at com.alibaba.excel.util.ClassUtils.lambda$declaredFields$6(ClassUtils.java:286)
at java.util.HashMap.computeIfAbsent(HashMap.java:1127)
at com.alibaba.excel.util.ClassUtils.declaredFields(ClassUtils.java:285)
at com.alibaba.excel.metadata.property.ExcelHeadProperty.initColumnProperties(ExcelHeadProperty.java:109)
at com.alibaba.excel.metadata.property.ExcelHeadProperty.<init>(ExcelHeadProperty.java:77)
at com.alibaba.excel.write.property.ExcelWriteHeadProperty.<init>(ExcelWriteHeadProperty.java:49)
at com.alibaba.excel.write.metadata.holder.AbstractWriteHolder.<init>(AbstractWriteHolder.java:222)
at com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder.<init>(WriteWorkbookHolder.java:168)
at com.alibaba.excel.context.WriteContextImpl.initCurrentWorkbookHolder(WriteContextImpl.java:107)
at com.alibaba.excel.context.WriteContextImpl.<init>(WriteContextImpl.java:90)
at com.alibaba.excel.write.ExcelBuilderImpl.<init>(ExcelBuilderImpl.java:36)
... 3 more
Caused by: java.lang.ClassNotFoundException: com.alibaba.excel.support.util.CollectionUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more
Process finished with exit code 1
java代码如下:
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.converters.date.DateStringConverter;
import java.io.File;
import java.io.IOException;
import java.util.Date;
public class DemoExport {
public static void main(String[] args) throws IOException {
File tempFile = File.createTempFile("demo", "test.xls");
ExcelWriter build = EasyExcel.write(tempFile, DemoRecord.class).build();
}
public static class DemoRecord {
@ExcelProperty("订单编号")
private String orderNumber;
@ExcelProperty(value = "下单时间", converter = DateStringConverter.class)
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private Date createdDate;
}
}
为了排除依赖,我是新建一个maven项目进行测试 ,依赖仅有easyexcel
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>export-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.0</version>
<!-- <version>3.2.1</version>-->
<!-- 3.2.1版本能够正常运行-->
</dependency>
</dependencies>
</project>
感谢菊苣的付出 . 比心