Spring3 Security JDBC如何加载连接信息
Spring3 Security JDBC 如何加载连接信息
我已经在 Spring3 Security JDBC 的这个示例上工作了 2 周,我让它工作了,但是将数据源添加到了 ApplicationContext 中,但现在我无法让它从我的文件加载连接信息。我对它进行了硬编码并且它可以工作,但我希望它从文件加载。有人可以告诉我我的 AppicationContext 中缺少什么才能使其正常工作吗..谢谢
ApplicationContext-Security.xml
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
</beans:bean
>
更改为以下内容并且有效:
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://127.0.0.1/db_mytest" />
<beans:property name="username" value="root" />
<beans:property name="password" value="" />
</beans:bean>
但我不想对其进行硬编码。请帮我。
Spring3 Security JDBC how to load connect info
I been working on this sample of Spring3 Security JDBC for 2 weeks now and I got it working but adding the dataSource been to the ApplicationContext but now I cant get it loading the connection inform from my file. I hard coded it and it works but I would like it to load from a file. can someone please tell me what I am missing from my AppicationContext to get it to work.. thanks
ApplicationContext-Security.xml
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
</beans:bean
>
Changed to following and it works:
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://127.0.0.1/db_mytest" />
<beans:property name="username" value="root" />
<beans:property name="password" value="" />
</beans:bean>
but I dont want to hard code it. please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以尝试将数据源设置指定到属性文件中,然后使用 PropertyPlaceholderConfigurer 包含属性文件,您可以在此博客中找到更多信息 http://www.summa-tech.com/blog/2009/04/20/6-使用 spring 管理属性文件的技巧/
Maybe you can try specifying the datasource settings into a properties file and then include the properties file using the PropertyPlaceholderConfigurer, you can find more info in this blog http://www.summa-tech.com/blog/2009/04/20/6-tips-for-managing-property-files-with-spring/