使用Spring JdbcMetadataStore(Oracle)时引发DuplicateKeyException

问题描述 投票:0回答:1

我当前的file:inbound-channel-adapter]配置>正常。我正在多台服务器上运行该应用程序,实际上只有一台正在处理该文件。数据库表INT_METADATA_STORE也已成功更新。我面临的问题是其中一台服务器仍在尝试插入记录,并且引发以下异常:

org.springframework.messaging.MessagingException: nested exception is
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; 
SQL [INSERT INTO INT_METADATA_STORE(METADATA_KEY, METADATA_VALUE, REGION) SELECT ?, ?, ? FROM INT_METADATA_STORE WHERE METADATA_KEY=? AND REGION=? HAVING COUNT(*)=0];
ORA-00001: unique constraint (SMS_OWNER.INT_METADATA_STORE_PK) violated; 
nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (SMS_OWNER.INT_METADATA_STORE_PK) violated

我尝试了不同的隔离方式,但没有运气。这与我在Spring Integration + Java中使用XML以来使用的事务管理器有关吗?请参阅下面的一些配置:

<int-file:inbound-channel-adapter directory="file:/tmp/input/" prevent-duplicates="true" filter="compositeFileListFilter">
  <int:poller max-messages-per-poll="1" cron="*/10 * * * * *">
    <int:transactional transaction-manager="transactionManager" isolation="READ_COMMITTED" timeout="5" />
  </int:poller>
</int-file:inbound-channel-adapter>

@Configuration
@EnableTransactionManagement
public class MetadataStoreConfiguration {

    @Value("${input.file.pattern:(DUMMY)(_).*\\.(xml)}")
    private String pattern;

    @Bean
    @Qualifier("fileSystemPersistentAcceptOnceFileListFilter")
    public FileSystemPersistentAcceptOnceFileListFilter fileSystemPersistentAcceptOnceFileListFilter(final DataSource dataSource) {
        return new FileSystemPersistentAcceptOnceFileListFilter(metadataStore(dataSource),"");
    }

    @Bean
    @Qualifier("metadataStore")
    public JdbcMetadataStore metadataStore(final DataSource dataSource) {
        JdbcMetadataStore metadataStore = new JdbcMetadataStore(dataSource);
        return metadataStore;
    }

    @Bean 
    public CompositeFileListFilter<File> compositeFileListFilter(FileSystemPersistentAcceptOnceFileListFilter fileSystemPersistentAcceptOnceFileListFilter) {       
        CompositeFileListFilter<File> filter = new CompositeFileListFilter<>(Arrays.asList(fileSystemPersistentAcceptOnceFileListFilter, new RegexPatternFileListFilter(pattern)));
        return filter;
    }

    @Bean
    @Primary
    public PlatformTransactionManager transactionManager(final DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

}

我正在使用Spring Boot 2.2.4.RELEASE

Java 8Oracle作为数据库。任何帮助将不胜感激。

我当前对file:inbound-channel-adapter的配置工作正常。我正在多台服务器上运行该应用程序,实际上只有一台正在处理该文件。数据库表...

spring-data-jpa spring-integration spring-jdbc
1个回答
0
投票

否,您的配置完全可以。真的没关系,因为在启动时它只能读取一次。在运行时,您只有Bean,并且已正确连接它们。因此,可以在Java配置中使用PlatformTransactionManagercompositeFileListFilter并将其用作XML one的引用。

© www.soinside.com 2019 - 2024. All rights reserved.