gpt4 book ai didi

java - Spring MVC 中的 Autowiring ViewResolver

转载 作者:行者123 更新时间:2023-11-30 04:48:00 24 4
gpt4 key购买 nike

由于某种原因,我无法 Autowiring ViewResolver:

@Component
public class JsonMultipleViewFactory
{
@Autowired
private ViewResolver viewResolver;

// ...
}

viewResolver 为 null

JsonMultipleViewFactory在Spring Controller 中 Autowiring :

@Controller
public class HomeController
{
@Autowired
private JsonMultipleViewFactory jsonMultipleViewFactory;

// ...
}

我创建了一个 github repository包含一个重现问题的很小的例子。

有人可以帮助我吗?

谢谢。

最佳答案

我的回答是your previous question ,没有答案:

In your example, JsonMultipleViewFactory is discovered through component scanning by parent context (applicationContext.xml). InternalResourceViewResolver is defined in child context (test-servlet.xml). So, is normal that parent context can't see beans defined in child context. This is the reason why you get a NoSuchBeanDefinitionException. Try to put all this beans in the same context.

关于java - Spring MVC 中的 Autowiring ViewResolver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10520771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com