XmlApplicationContext:有没有办法立即知道所有配置问题?

发布于 2025-01-01 10:51:00 字数 75 浏览 3 评论 0 原文

XmlApplicationContext 在第一个与类定义不匹配的 XML 定义上返回异常。有没有办法获取 XML 中所有问题的列表?

XmlApplicationContext returns an exception on the first XML definition that does not match a class definition. Is there a way to get a list of all problems in my XML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吖咩 2025-01-08 10:51:00

不,没有这样的选择。如果容器遇到错误,那么它的依赖关系就会被破坏,并且不知道这将如何影响配置的其余部分。最安全的事情就是当场失败。

在为 Spring.NET 制作 xml 配置时遇到问题是很常见的。您输错了类名、属性名或构造函数类型,并在运行(或集成测试)应用程序时找出答案。你修复它,再次运行它,却发现你在下一行犯了类似的错误。这可能会令人沮丧,所以我完全理解你的问题来自哪里。

您可以采取一些措施来最大限度地减少 xml 配置中的错误:

  • 安装 Spring xsd 文件”部分 - 这将在您键入 xml 时验证您的 xml。
  • 安装 Spring.NET Visual Studio Addin,需要 VS 2010。这将为您提供:
    • 类似智能感知的类型完成、属性名称完成和构造函数参数名称完成。
    • 一些 xml 片段,用于快速插入对象定义等。
    • SDK 快速信息工具提示
    • 观看此视频了解演示
  • 如果您不运行 VS 2010,您还可以查看一些的功能Resharper 对 Spring.NET 很有用,

我建议两者都做。我认为安装插件也会安装 xsd 文件。

您还可以考虑将(部分)配置切换到 Spring.NET 的 CodeConfig,但那就是超出了这个问题的范围。

No there isn't such an option afaik. If the containers encounters an error, then it has got a broken dependency and has got no idea how this would effect the remainder of the configuration. Safest thing is to fail right then and there.

It is very common to encounter problems when crafting xml configuration for Spring.NET. You mistype a class name, property name or constructor type and find out when you run (or integration-test) your application. You fix it, run it again, only to find out you made a similar error on the next line. This can get frustrating, so I fully understand where your question comes from.

There are a few things you can do to minimize making errors in your xml configuration:

  • Install the Spring xsd files in Visual Studio - this will validate your xml while you type it.
  • Install the Spring.NET Visual Studio Addin, requires VS 2010. This will give you:
    • Intellisense-like type completion, property name completion and constructor argument name completion.
    • Some xml snippets to quickly insert object definitions and more.
    • SDK quick info tooltips
    • See this video for a demo
  • If you don't run VS 2010, you can also checkout some of the features of Resharper that are useful for Spring.NET

I recommend doing both. I think installing the add in also installs the xsd files.

You can also consider switching (parts of) you configuration to Spring.NET's CodeConfig, but that's beyond the scope of this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文