把我所有的豆子放在不同的文件中

发布于 2025-01-04 07:21:26 字数 1085 浏览 4 评论 0原文

我正在使用 spring mvc 和 spring security。在我的 security-app-context.xml 中,我有:

<authentication-manager>
    <authentication-provider user-service-ref="MyUserDetailsService"/>
</authentication-manager>

因此我需要在此 security-app-context.xml 文件中配置 MyUserDetailsS​​ervice 。所以我添加了:

<beans:bean id="MyUserDetailsService"
            class="my.web.authentication.GreenWheelsUserDetailsService">
    <beans:property name="transactionManager" ref="transactionManager"/>
    <beans:property name="userDao" ref="userDao"/>
</beans:bean>

但这导致我也将 transactionManageruserDao bean 添加到该文件中!所以我补充道:

<beans:bean id="transactionManager" class="my.dataAccess.hibernate.HibernateTransactionManager"/>
    <beans:bean id="userDao" class="my.dataAccess.hibernate.HibernateUserDao"/>

但现在我想为其他 DAO 添加另一个 beans。我更喜欢将所有 bean 放在不同的文件中,然后放在 security-app-context.xml 文件中。我该如何做到这一点并保持 authentication-manager 部分正确?

I am using spring mvc and spring security. In my security-app-context.xml I have:

<authentication-manager>
    <authentication-provider user-service-ref="MyUserDetailsService"/>
</authentication-manager>

And therefore I need to configure MyUserDetailsService in this security-app-context.xml file. So I added:

<beans:bean id="MyUserDetailsService"
            class="my.web.authentication.GreenWheelsUserDetailsService">
    <beans:property name="transactionManager" ref="transactionManager"/>
    <beans:property name="userDao" ref="userDao"/>
</beans:bean>

But this cause me to add transactionManager and userDao beans to this file too! So I added:

<beans:bean id="transactionManager" class="my.dataAccess.hibernate.HibernateTransactionManager"/>
    <beans:bean id="userDao" class="my.dataAccess.hibernate.HibernateUserDao"/>

But now I want to add anothr beans for other DAOs. I prefer to put all my beans in different file then the security-app-context.xml file. How do I do that and keep the authentication-manager section correct?

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

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

发布评论

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

评论(2

如痴如狂 2025-01-11 07:21:26

您可以使用导入:

<beans:import resource="beans.xml" />

You can use import:

<beans:import resource="beans.xml" />
阳光下的泡沫是彩色的 2025-01-11 07:21:26

您可以使用 spring;将任何文件导入到您的 spring 安全文件中。

You can use the spring <beans:import resource="someotherfile.xml" /> to import any file into your spring security file.

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