在Entity上加了@Entity注解,且是javax.persistence.Entity的。Application.java上也加了@ComponentScan。为什么感觉扫不到这个Entity呢?
原因如下:(标红字的地方一定要写对了,否则扫描不到该Entity)
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.springboot.wt.entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="jdbc.use_scrollable_resultset">false</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext
</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
</props>
</property>
</bean>
博友们,sessionfactory的packagestoscan和<context:component-scan base-package="" />有什么关系??
答案一:packagesToScan是扫描实体类的