在Spring.config中,我可以定义字符串类型的对象吗?
我可以做这样的事情:
<object id="mydb" type="string">
<value>"blah"</value> <-- note that <value> tag does not really exist
</object>
这样我以后就可以像这样使用它:
<object id="Someobject" type="Sometype">
<property name="ConnectionString" ref="mydb"/>
</object>
编辑:这是我正在寻找的 SpringFramework.NET 解决方案。 看起来 PropertyPlaceholderConfigurer 也存在那里。 谢谢大家。
Can I do something like this:
<object id="mydb" type="string">
<value>"blah"</value> <-- note that <value> tag does not really exist
</object>
So that I could use it later like so:
<object id="Someobject" type="Sometype">
<property name="ConnectionString" ref="mydb"/>
</object>
EDIT: this was SpringFramework.NET solution I was looking for. Looks like PropertyPlaceholderConfigurer exists there too. Thanks everybody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Spring 内置的 PropertyPlaceholdConfigurer:
设置
SYSTEM_PROPERTIES_MODE_OVERRIDE
允许通过命令行覆盖属性。Use Spring's built-in PropertyPlaceholdConfigurer:
Setting
SYSTEM_PROPERTIES_MODE_OVERRIDE
allows overriding the property via the command line.使用占位符,例如 ${magic} 并在属性文件中定义键/值以及后处理器。 Google for spring 后处理器占位符...
Use placeholders eg ${magic} and define the key/value in a properties file along with a PostProcessor. Google for spring post processor placeholder...
我根本看不出你的方式有什么好处。 这一切仍然只是配置。
有时,人们将数据库连接字符串外部化到 .properties 文件中并以这种方式获取它们。 我认为这比你的建议更有意义。
I don't see any advantage to your way at all. It's all still just configuration.
Sometimes people externalize database connection strings to a .properties file and get at them that way. I think that makes more sense than your proposal.