私は、保持するクラスを含むパッケージ(packagesToScan
)に@Entity
と注釈を付けました。PackagesToScanをスキャン中にいくつかのクラスを無視する
ApplicationContext
の設定を定義するとき、私は以下のようにしました。
@Configuration
@EnableJpaRepositories("packagesToScan")
@EnableTransactionManagement
@PropertySource("server/jdbc.properties")
@ComponentScan("packagesToScan")
public class JpaContext {
... // Other configurations ....
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(this.dataSource());
emf.setJpaVendorAdapter(this.jpaVendorAdapter());
emf.setPackagesToScan("packagesToScan");
emf.setJpaProperties(this.hibernateProperties());
return emf;
}
開発している間、私は私が実行を許可されていませんよ(なし主キーなどのような)持続性の要件を満たし、これに起因していませんpackagesToScan
内のいくつかのクラスをしましたテストのためにApplicationContext
が失敗しました。
今、 一部の選択されたクラスをスキャンするか、または一部のクラスを無視する方法はありますかpackagesToScan
?私はあることをどのクラスフィルタリングするために使用することができますLocalSessionFactoryBean
クラスのsetEntityTypeFilters
functionがあることに気づき
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan" value="com.mycompany.bean"/>
<property name="entityTypeFilters" ref="packagesToScanIncludeRegexPattern">
</property>
<property name="hibernateProperties">
// ...
</property>
</bean>
<bean id="packagesToScanIncludeRegexPattern" class="org.springframework.core.type.filter.RegexPatternTypeFilter" >
<constructor-arg index="0" value="^(?!com.mycompany.bean.Test).*"/>
</bean>
:私は同じ問題を解決しようと最終的には以下のように解決策を持ってきた
あなたのエンティティが完了するまで、@Entity注釈を削除/コメントすることができます。それは永続性プロバイダによって選択されません。 –
テストしたい特定のエンティティだけをスキャンすることはできませんか? – TheKojuEffect
packagesToScanオプションを削除し、persistence.xmlを作成してここにエンティティをリストアすることもできます。私はまだいくつかのエンティティを除外するあなたの動機を理解していません - 開発の途中でエンティティが完了していない場合、または何か不足している場合@Entityアノテーションを簡単に削除できますか? –