【问题标题】:Spring Framework Unable to Resolve References in IntelliJSpring Framework 无法解析 IntelliJ 中的引用
【发布时间】:2014-08-29 22:19:41
【问题描述】:

我为spring设置了一个应用配置文件,将其添加到facets中,并根据另一个完美运行的配置文件进行设置。 所有对 spring 组件的引用都是可见的并且似乎可以工作,但是对 xml 文件中的项目的所有引用都找不到。

一个例子是任务:

<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler" />

taskScheduler 和 taskExecutor 都无法解析。结果,任务 bean 永远不会设置,所以我所有的 @Scheduled 注释都不会工作。

为服务设置工厂提供者工作正常(所有@Service 和@Autowired 注释都有效),所以我完全确定问题出在项目中的一些配置问题上。

还需要在 IntelliJ 中配置哪些 bean 才能工作?为什么spring不重新扫描文件来查找对bean的引用?

这里是所有 springframework bean 的引用:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:task="http://www.springframework.org/schema/task"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/task
   http://www.springframework.org/schema/task/spring-task-3.1.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/cache
   http://www.springframework.org/schema/cache/spring-cache.xsd"
   default-lazy-init="true">

【问题讨论】:

  • 你遇到了什么错误?
  • 错误是“taskScheduler 和 taskExecutor 都无法解决”,所以所有计划任务都不起作用。在 spring.xml 中引用另一个 bean 的其他 bean 都不起作用。

标签: java spring intellij-idea


【解决方案1】:

问题在于应用程序配置文件有多个上下文。要修复它,请转到 IntelliJ 中的配置文件,然后在顶部有一个部分,您可以在其中选择要将上下文文件放入哪个应用程序上下文(读取类似“模块 [您的模块] 中的 Spring 应用程序上下文。文件包含在 [n] 个上下文中”)。尝试选择每一个,直到参考解决;它将从其他上下文中删除它。我的特殊问题是它在 MVC 上下文中,它需要在 Spring 应用程序上下文中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-07
    • 2015-01-06
    • 2022-01-14
    • 2013-12-09
    • 2021-05-30
    • 2014-05-09
    • 2015-05-23
    • 1970-01-01
    相关资源
    最近更新 更多