"-6ren"> "-我正在尝试从 Spring 4.x 升级到 Spring 5.x,但遇到一个问题。我在META-INF\spring\abc\中有多个spring xml配置文件目录。在 META-INF\sprin-6ren">
gpt4 book ai didi

java - 从 Spring 4.x 升级到 5.x 时获取 "InvalidPathException: Illegal char <*>"

转载 作者:行者123 更新时间:2023-12-01 23:08:26 28 4
gpt4 key购买 nike

我正在尝试从 Spring 4.x 升级到 Spring 5.x,但遇到一个问题。我在META-INF\spring\abc\中有多个spring xml配置文件目录。在 META-INF\spring\我有目录abc-context.xml文件包含以下行:

<!-- Spring Bean Profiles will ensure only one instance is loaded based on -Dinstance=[name] -->
<import resource="abc/*.xml"/>

当我使用 Spring 4.x 运行应用程序时,一切正常。日志摘录:

DEBUG PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [C:\...\abc\target\classes\META-INF\spring\abc]
DEBUG PathMatchingResourcePatternResolver - Searching directory [C:\...\abc\target\classes\META-INF\spring\abc] for files matching pattern [.../abc/target/classes/META-INF/spring/abc/*.xml]
DEBUG PathMatchingResourcePatternResolver - Resolved location pattern [file:.../abc/target/classes/META-INF/spring/abc/*.xml] to resources [file [C:\...\abc\target\classes\META-INF\spring\abc\pqr.xml], file [C:\...\abc\target\classes\META-INF\spring\abc\mno.xml], file [C:\...\abc\target\classes\META-INF\spring\abc\xyz.xml]]

当我升级到 Spring 5.x 并尝试运行该应用程序时,出现以下异常:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [...\target\classes\META-INF\spring\abc-context.xml]; nested exception is java.nio.file.InvalidPathException: Illegal char <*> at index 88: ...\target\classes\META-INF\spring\abc\*.xml
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:419)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
at org.springframework.context.support.GenericXmlApplicationContext.load(GenericXmlApplicationContext.java:130)
at com.nomura.unity.stp.model.camel.UnityStpMain.createDefaultApplicationContext(UnityStpMain.java:69)
at org.apache.camel.spring.Main.doStart(Main.java:154)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:138)
at org.apache.camel.main.MainSupport.run(MainSupport.java:390)
at com.nomura.unity.stp.model.camel.UnityStpMain.main(UnityStpMain.java:81)
at com.nomura.unity.stp.audit.Main.main(Main.java:12)
Caused by: java.nio.file.InvalidPathException: Illegal char <*> at index 88: ...\target\classes\META-INF\spring\abc\*.xml
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.io.File.toPath(File.java:2234)
at org.springframework.core.io.FileSystemResource.<init>(FileSystemResource.java:82)
at org.springframework.core.io.FileSystemResource.createRelative(FileSystemResource.java:310)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:248)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:191)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:176)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:513)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:393)
... 14 more

有人可以帮我理解为什么 * 在这里被视为非法字符吗?有什么解决办法吗?

PS:我知道我可以有多个 bean 配置文件定义并相应地导入文件,但我不想这样做,因为这对我来说在许多(200 多个)应用程序中将是一个额外的更改。

最佳答案

我已经找到解决方案了。

改变这个

<import resource="abc/*.xml"/>

到此

<import resource="classpath:META-INF/spring/abc/*.xml"/>

解决了问题。

关于java - 从 Spring 4.x 升级到 5.x 时获取 "InvalidPathException: Illegal char <*>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58388659/

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