在我的春季项目中,我们使用的web依赖项包含配置applicationContext.xml
和security-config.xml
。我必须在我的申请中改变这两个方面,我该如何实现这一点。
我期待这样的
compile (librariesdependencyname) {
exclude ('applicationContext.xml')
exclude ('common-security-config.xml')
}
如果您的团队正在处理jar。只需要求他们创建新版本,并且没有此配置和资源文件
或
您可以修改上下文加载程序的操作和模式,如下面的
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml,classpath*:/**/*-config.xml</param-value>
</context-param>
有关项目设置的更多信息将有助于提供更准确的建议。可以通过多种方式实现。
假设你有以下
- Library提到了xml文件
- 我们想要的是代码而不是配置
正如@Araf所提到的,我们可以请求团队更新库并更改配置
- 通过这种方式重新构造代码以提供自动配置文件库的使用者可以选择是否通过自动加载加载配置
- 定义您自己要加载的xml文件,这样它就不会加载库配置
中提到的实现自动配置机制的一种方法https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-自动配置或者,由于这是您自己的项目,您可以尝试多模块项目https://www.baeldung.com/spring-boot-multiple-modules
选择要加载或排除的包,我们可以使用@ComponentScan
https://www.baeldung.com/spring-component-scanning.
XML版本的注释应该是可用的,我个人更喜欢注释,因为它将使用代码作为配置。
您可以在gradle中添加自定义任务,而不是添加您的jar compile"依赖性。将其定义为"某事">依赖关系。使用配置访问it对象"某事">。参考以下示例
librariesdependency "<<package-librariesdependencyname>>"
jar.dependsOn 'customJar'
task customJar (type: Jar) {
archiveName = 'your-output.jar'
from zipTree(configurations.librariesdependency.singleFile)
exclude 'applicationContext.xml'
}