gpt4 book ai didi

Dozer 文件未找到异常

转载 作者:行者123 更新时间:2023-12-01 19:15:46 26 4
gpt4 key购买 nike

我正在尝试执行下面的推土机示例。我的 xml 文件与 java 文件位于同一位置,但我收到文件未找到异常

Exception in thread "main" org.dozer.MappingException: Unable to locate dozer mapping file [dozerMapping.xml] in the classpath!
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:87)
at org.dozer.util.MappingValidator.validateURL(MappingValidator.java:63)
at org.dozer.loader.CustomMappingsLoader.loadFromFiles(CustomMappingsLoader.java:101)
at org.dozer.loader.CustomMappingsLoader.load(CustomMappingsLoader.java:56)
at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:213)
at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:186)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at com.mapping.CopyAttributes.main(CopyAttributes.java:28)

如果我给出完整的文件路径,它正在工作,但我收到以下异常

Exception in thread "main" org.dozer.MappingException: java.net.MalformedURLException: unknown protocol: c
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.util.ResourceLoader.getResource(ResourceLoader.java:57)
at org.dozer.util.DefaultClassLoader.loadResource(DefaultClassLoader.java:44)
at org.dozer.util.MappingValidator.validateURL(MappingValidator.java:61)
at org.dozer.loader.CustomMappingsLoader.loadFromFiles(CustomMappingsLoader.java:101)
at org.dozer.loader.CustomMappingsLoader.load(CustomMappingsLoader.java:56)
at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:213)
at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:186)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at com.mapping.CopyAttributes.main(CopyAttributes.java:28)
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.dozer.util.ResourceLoader.getResource(ResourceLoader.java:55)

源代码

    String file = "C:/UnitTest/Dozer/src/com/mapping/mapping.xml";
DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));

最佳答案

好的。我解决了这个问题..

我将文件放入 resources/META-INF/dozerBeanMapping.xml 并使用以下方式访问该文件:

String file = "META-INF/dozerBeanMapping.xml";

DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));

希望这对你们也有帮助。

关于Dozer 文件未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8364791/

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