4

我正在尝试执行下面的推土机示例。我的 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}));
4

2 回答 2

7

好的。我解决了这个..

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

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

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

我希望这对你们也有帮助。

于 2012-07-02T06:08:39.497 回答
0

您正在使用String file = "C:/..."并且错误提到它不能将 C 识别为有效协议。

您应该尝试file://C:/...改用 - 它可能会有所帮助。如果没有,请尝试使用双反斜杠 ( C:\\UnitTest\\...),如果这不起作用,只需将文件上传到某处

于 2011-12-03T01:41:25.660 回答