Spring Root Context创建了两次

时间:2019-01-17 18:24:40

标签: java spring

我的应用程序是一个微服务,我可以将其编译成战争并部署到Wildfly 12中(主要是出于方便,我根本不使用Web上下文)。我在XML配置中使用“香草”弹簧。一旦我的应用程序启动,我就可以在日志中看到所有bean都创建了两次。似乎这些重复的豆在某个时间点似乎被无故摧毁。

web.xml仅包含以下内容:

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:config.xml</param-value>
</context-param>

大多数类似问题的答案都提到,如果文件名包含servlet的名称,spring会自动选择配置,但是在我的情况下不是这样。

1 个答案:

答案 0 :(得分:0)

看起来是由config.xml中的以下行引起的:

<jpa:repositories base-package="(...)"/>

删除这些行之后,所有的bean只注入一个,并且上下文不会被破坏。