Spring.NET XML 配置问题
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来好像“众所周知的命名空间解析器”的发现和注册出了问题。要解决此问题,请尝试在 XML 文件本身中声明命名空间别名,如...
...然后查看是否正常工作。您使用的 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...
...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--?