【问题标题】:Can I autowire (and autodiscover) daos while specifying the entities through a hibernate config?我可以在通过休眠配置指定实体时自动装配(和自动发现)daos 吗?
【发布时间】:2012-03-14 18:56:48
【问题描述】:

基本上,我有需要成为实体的对象,但是生成了代码并且我无法触摸它(因此我无法使用注释)。我想在 xml 配置中列出它们。但是,我也希望 spring 自动发现和自动连接各自的 daos。我将如何设置我的配置?

【问题讨论】:

    标签: spring hibernate jpa annotations autowired


    【解决方案1】:

    您可以根据需要配置组件扫描(顺便说一句:您可以进行多个组件扫描)

    <context:component-scan base-package="org.example" use-default-filters="false">
        <context:include-filter type="regex" expression=".*Dao"/>
    </context:component-scan>
    

    此示例将为所有匹配正则表达式并位于基础包中的类创建 bean。

    @见Spring Reference Chapter 3.10.3 Using filters to customize scanning

    【讨论】:

    • 啊哈!这就是我需要的。显然我没有在正确的地方“寻找”(我的一些 daos 在不同的包中)。
    猜你喜欢
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 2023-03-10
    • 2017-05-11
    • 2014-02-02
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    相关资源
    最近更新 更多