简体   繁体   English

Maven依赖项在Spring配置中不可见

[英]Maven dependency not visible in Spring configuration

I have a depedency project called myjar. 我有一个名为myjar的去污项目。 I installed it in my local Maven repository. 我将其安装在本地Maven存储库中。

Then in my main project, I included the dependency in my pom.xml: 然后在我的主项目中,将依赖项包含在pom.xml中:

<dependency>
    <groupId>com.mygroupid</groupId>
    <artifactId>myjar</artifactId>
    <version>1.0</version>
</dependency>

Now I have some Spring configuration in my main project where I want to refer to the dependency jar: 现在我的主项目中有一些Spring配置,我想在其中引用依赖项jar:

<list>
    <value>myjar-1.0.jar</value>
</list>

But the above line of code doesn't work. 但是上面的代码行不起作用。

However I don't want to create a uber-jar with all the dependencies, I just want my dependency to be accessed from the local repository. 但是,我不想创建带有所有依赖项的uber-jar,我只想从本地存储库访问我的依赖项。

So how should I rewrite the above Spring configuration in order to do that? 那么我该如何重写上面的Spring配置呢?

Since that Maven dependency has compile scope, the contents of that JAR are going to be available on the classpath of your application. 由于该Maven依赖项具有编译范围,因此该JAR的内容将在您的应用程序的类路径上可用。 Instead of trying to refer to the JAR to get your hands on the mapping files, get them from the classpath, as in this answer , ie using mappingLocations and classpath:...file.xml . 与其尝试参考JAR来获取映射文件,不如在此答案中那样,从类路径中获取它们,即使用mappingLocationsclasspath:...file.xml

If that doesn't work for some reason and you really need to reference the JAR file, the parameter of mappingJarLocations is a Spring resource. 如果由于某种原因该方法不起作用,并且您确实需要引用JAR文件,则mappingJarLocations的参数是Spring资源。 If you're not in a Servlet container, you can use file:///path/to/jar and if you are in a Servlet container, you can pull it from WEB-INF/lib as in the linked answer. 如果您不在Servlet容器中,则可以使用file:///path/to/jar ;如果您在Servlet容器中,则可以按照链接的答案将其从WEB-INF/lib拉出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM