如果有@Entity,为什么需要"annotatedClasses"?

Fix*_*xus 16 spring annotations hibernate

您好我正在构建spring-hibernate应用程序.我真的需要从下面配置吗?

    <property name="annotatedClasses">
        <list>
            <value>org.fixus.springer.model.User</value>
        </list>
    </property>
Run Code Online (Sandbox Code Playgroud)

我在root-context.xml中设置了注释驱动

<mvc:annotation-driven />
<context:component-scan base-package="org.fixus.springer" />
<context:component-scan base-package="org.fixus.springer.model" />
Run Code Online (Sandbox Code Playgroud)

现在不应该自动从这个带有注释@Entity的包中取出所有内容并将其转换为表吗?至于现在没有annotatedClasses,他不会从实体创建一个表

Tom*_*icz 29

使用文档,卢克!

[...] AnnotationSessionFactoryBean bean定义的示例:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="annotatedClasses">
        <list>
            <value>test.package.Foo</value>
            <value>test.package.Bar</value>
        </list>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

或者在使用类路径扫描进行实体类的自动检测时:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="test.package"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

如您所见,您可以选择明确定义所有类还是仅定义扫描包.<context:component-scan/>不识别Hibernate/JPA注释,因此没有效果.