我正在尝试在ElementProcessor中使用@Autowired。 (http://www.thymeleaf.org/doc/extendingthymeleaf.html#some-reasons-to-extend-thymeleaf)
@Configurable(dependencyCheck = true)
public class AuditLogElementProcessor extends AbstractMarkupSubstitutionElementProcessor {
@Autowired(required = true)
DocumentService docService;
但不知何故,对象docService始终为null。 代码本身是定义工作的。 我已经尝试过使用LTW,它使用完全相同的代码(但我不允许使用LTW)。
您是否有任何想法如何将我的服务注入我的ElementProcessor?
谢谢!
答案 0 :(得分:1)
解答:
自己找到它。 问题是ElementProcessor无法访问服务,因为只在需要时才创建处理器。
解决方案: 在Dialect(创建处理器)中自动连接所需的所有服务,并将所有服务作为参数传递给处理器。
它以这种方式工作