配置spring应用程序时的NullPointer

时间:2015-10-19 08:54:29

标签: spring spring-batch

我的PartnerBillingConfig类可以完成大部分配置。现在我以前看到在配置对象中使用@Value不会设置@PropertySource定义的属性,所以我把这些值放到一个用@Component修饰的单独的类中,但是没有一个bean连接到PartnerBillingConfig

PartnerBillingConfig.java

@ComponentScan(basePackages = {"com.vitel"})
@Configuration
@EnableBatchProcessing
@EnableAspectJAutoProxy
public class PartnerBillingConfig {

    @Autowired
    private AppProps appProps;

    @Autowired
    private DatasourceSupplierTasklet dsSupplier;

    @Autowired
    private NextDatasourceDecision dsDecision;

    @Bean
    public DataSource partnerBillingDs() {
        final HikariConfig cfg = new HikariConfig();
        cfg.setJdbcUrl(appProps.getPartnerBillingUrl());
        cfg.setDataSourceClassName(appProps.getPartnerBillingDatasource());
        cfg.setUsername(appProps.getPartnerBillingUsername());
        cfg.setPassword(appProps.getPartnerBillingPassword());
        cfg.addDataSourceProperty("cachePrepStmts", appProps.getCachePrepStatements());
        cfg.addDataSourceProperty("prepStmtCacheSize", appProps.getPrepStatementCacheSize());
        cfg.addDataSourceProperty("prepStmtCacheSqlLimit", appProps.getPrepStatementCacheSqlLimit());

        HikariDataSource ds = new HikariDataSource(cfg);

        return ds;
    }

    @Bean
    public JdbcTemplate partnerBillingTemplate() {
        return new JdbcTemplate(partnerBillingDs());
    }

AppProps.java

@Component
public class AppProps {
    @Value("${cdr.start.date}")
    private String startDate;
    @Value("${cdr.end.date}")
    private String endDate;

    @Value("${fetch.size}")
    private Integer fetchSize;
    @Value("${chunk.size}")
    private Integer chunkSize;
    @Value("${paging.size}")
    private Integer pagingSize;

    @Value("${partner.billing.jdbc.url}")
    private String partnerBillingUrl;
    @Value("${partner.billing.jdbc.datasource}")
    private String partnerBillingDatasource;
    @Value("${partner.billing.jdbc.username}")
    private String partnerBillingUsername;
    @Value("${partner.billing.jdbc.password}")
    private String partnerBillingPassword;

    @Value("${jdbc.cache.prepared.statements}")
    private Boolean cachePrepStatements;
    @Value("${jdbc.prepared.statement.cache.size}")
    private Integer prepStatementCacheSize;
    @Value("${jdbc.prepared.statement.cache.sql.limit}")
    private Integer prepStatementCacheSqlLimit;

记录缩写:

DEBUG org.springframework.core.env.StandardEnvironment - Adding [class path resource [test.properties]] PropertySource with lowest search precedence
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.TestConfiguration.testDb()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registered bean definition for imported class 'org.springframework.batch.core.configuration.annotation.ScopeConfiguration'
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.ScopeConfiguration.stepScope()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.ScopeConfiguration.jobScope()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registered bean definition for imported class 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration'
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobRepository()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobLauncher()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobRegistry()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobExplorer()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.transactionManager()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobBuilders()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.stepBuilders()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.partnerBillingDs()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.partnerBillingTemplate()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.cdrReader()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.cdrWriter()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.createJob()
DEBUG org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method com.mhgad.za.vitel.billing.batch.PartnerBillingConfig.propPlaceholder()

我的代码在github上,因为IIRC发布链接在这里是一个失礼

0 个答案:

没有答案