Spring.NET XML 配置问题

发布于 2024-10-16 06:30:16 字数 2485 浏览 2 评论 0原文

我正在尝试从 XML 文件加载 Spring.NET 上下文。我有以下代码:

public class ApplicationContextFactory
{
    private static IApplicationContext _context;
    public static IApplicationContext GetContext()
    {
        if (_context == null)
        {
            try
            {
                string data = new StreamReader(
                       Assembly.GetExecutingAssembly().
                       GetManifestResourceStream("Nmspace.Fldr.spring-config.xml"))
                       .ReadToEnd();
                using (var temp = File.CreateText("ctx.xml"))
                    temp.WriteLine(data);
                _context = new XmlApplicationContext("ctx.xml");
               // _context = new XmlApplicationContext(
                    //"assembly://DataLoader/DataLoader/Config.spring-config.xml");
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
        return _context;
    }
}

我收到以下异常:

文件 [D:\ Correct\path\to\ctx.xml] 中的 XML 文档中的第 25 行违反了架构。未声明 'http://www.springframework.net/database:provider' 元素。

如果我直接从程序集中拉出,我会得到同样的错误。 (注释掉行。)

真正奇怪的是,直到我开始一个新项目并尝试在我的新项目中使用该配置之前,我没有遇到任何问题。 (此代码和配置文件在旧项目中已经工作了几个月,而且仍然有效。)

编辑:

Xmlns 声明:

<objects
    xmlns="http://www.springframework.net"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.net/tx"
    xmlns:db="http://www.springframework.net/database"
    xmlns:aop="http://www.springframework.net/aop"
    xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects.xsd
        http://www.springframework.net/schema/tx http://www.springframework.net/schema/tx/spring-tx-1.1.xsd
        http://www.springframework.net/schema/db http://www.springframework.net/schema/db/spring-database.xsd
        http://www.springframework.net/aop http://www.springframework.net/schema/aop/spring-aop-1.1.xsd"
>

问题行 (25):

<db:provider
    id="localDbProvider"
    provider="OracleClient-2.0"
    connectionString=
        "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = xe))); User Id=cmdb; Password=password;"/>

I'm trying to load a Spring.NET context from an XML file. I have the following code:

public class ApplicationContextFactory
{
    private static IApplicationContext _context;
    public static IApplicationContext GetContext()
    {
        if (_context == null)
        {
            try
            {
                string data = new StreamReader(
                       Assembly.GetExecutingAssembly().
                       GetManifestResourceStream("Nmspace.Fldr.spring-config.xml"))
                       .ReadToEnd();
                using (var temp = File.CreateText("ctx.xml"))
                    temp.WriteLine(data);
                _context = new XmlApplicationContext("ctx.xml");
               // _context = new XmlApplicationContext(
                    //"assembly://DataLoader/DataLoader/Config.spring-config.xml");
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
        return _context;
    }
}

I'm receiving the following exception:

Line 25 in XML document from file [D:\correct\path\to\ctx.xml] violates the schema. The 'http://www.springframework.net/database:provider' element is not declared.

I get the same error if I pull directly from the assembly. (Commented out lines.)

What's really weird is that I was having no problems until I started a new project and tried to use the configuration in my new project. (This code and configuration file has worked for months in old projects, and still does.)

Edit:

Xmlns declarations:

<objects
    xmlns="http://www.springframework.net"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.net/tx"
    xmlns:db="http://www.springframework.net/database"
    xmlns:aop="http://www.springframework.net/aop"
    xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects.xsd
        http://www.springframework.net/schema/tx http://www.springframework.net/schema/tx/spring-tx-1.1.xsd
        http://www.springframework.net/schema/db http://www.springframework.net/schema/db/spring-database.xsd
        http://www.springframework.net/aop http://www.springframework.net/schema/aop/spring-aop-1.1.xsd"
>

The problem line (25):

<db:provider
    id="localDbProvider"
    provider="OracleClient-2.0"
    connectionString=
        "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = xe))); User Id=cmdb; Password=password;"/>

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

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

发布评论

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

评论(1

一紙繁鸢 2024-10-23 06:30:16

听起来好像“众所周知的命名空间解析器”的发现和注册出了问题。要解决此问题,请尝试在 XML 文件本身中声明命名空间别名,如...

<objects xmlns='http://www.springframework.net'
     xmlns:database="http://www.springframework.net/database">
    ...
</objects>

...然后查看是否正常工作。您使用的 Spring.NET 版本是什么?它是否与您过去的项目中使用的版本相同,其中相同的名称空间别名会自动为您发生?

Sounds like something has gone wrong with the discovery and registration of the 'well-known-namespace-parsers'. To troubleshoot this, try to declare the namespace alias in the XML file itself as in...

<objects xmlns='http://www.springframework.net'
     xmlns:database="http://www.springframework.net/database">
    ...
</objects>

...and then see if that works properly. What version of Spring.NET are you using? And is it the same version that is in use in your past project(s) where this same namespace aliasing happens automatically for you--?

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