与自定义配置春季启动应用程序服务器上不加载(的WebSphere)启动

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

我有一个连接到使用MyBatis的两个数据源弹簧启动应用程序。春季启动在服务器启动时不加载,我已经检查了服务器启动过程中的日志,我没有看到任何弹簧引导它有关的消息。如开始在服务器启动后,WAS控制台显示应用程序的状态。

该应用程序无法正常工作,直到我重新启动它,并重新启动应用程序时,我可以看到在日志春季启动相关的消息。它重新启动后,该应用程序工作正常。

服务器版本:IBM WebSphere应用服务器网络部署(8.5.5.14)Java版本:8.0.2.10(IBM的WebSphere SDK Java技术版)

@SpringBootApplication
@ComponentScan(basePackages="org.sample.solve.*")
@MapperScan("org.sample.solve.sa.db.mappers")
public class SampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

配置:

package org.sample.solve.sa;

import .....

@Configuration
public class MybatisDBConfig  {

    private final Logger log = LoggerFactory.getLogger(this.getClass());
    public static final String SQL_SESSION_FACTORY_NAME_1 = "sqlSessionFactory1";
    public static final String SQL_SESSION_FACTORY_NAME_2 = "sqlSessionFactory2";

    public static final String MAPPERS_PACKAGE_TSC      = "org.sample.solve.sa.db.mappers"; // mapper interface package
    public static final String MAPPERS_PACKAGE_SERVICES_DB  = "org.sample.solve.sa.db.services_db.mappers"; // mapper interface package

    @Profile("local")
    @Bean(name = "tscDB")
    @Primary
    @ConfigurationProperties(prefix = "sp.firstDatasource")
    public DataSource dataSource1() {
        DataSource dataSource = null;
        try {
            dataSource = DataSourceBuilder.create().build();
            log.info("tsc datasource");
        }catch(Exception excep) {
            excep.printStackTrace();
        }
        return dataSource;
    }

    @Profile("local")
    @Bean(name = "servicesDB")
    @ConfigurationProperties(prefix = "sp.secondDatasource")
    public DataSource dataSource2() {
        DataSource dataSource = null;
        try {
            dataSource = DataSourceBuilder.create().build();
            log.info("services datasource");
        }catch(Exception excep) {
            excep.printStackTrace();
        }
        return dataSource;
    }


    @Profile({"dev", "fvt", "uat", "prod"})
    @Bean(name = "tscDB")
    @Primary
    public DataSource primaryDataSource() {
        System.out.println("sacpDS_JNDI : jdbc/QAServiceSACP");
        JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        DataSource dataSource = dataSourceLookup.getDataSource("jdbc/QAServiceSACP");
        return dataSource;
    }

    @Profile({"dev", "fvt", "uat", "prod"})
    @Bean(name = "servicesDB")
    public DataSource secondaryDataSource() {
        System.out.println("servicesDS_JNDI : jdbc/servicesDS");
        JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        DataSource dataSource = dataSourceLookup.getDataSource("jdbc/servicesDS");
        return dataSource;
    }

    @Bean(name = SQL_SESSION_FACTORY_NAME_1)
    @Primary
    public SqlSessionFactory sqlSessionFactory1(@Qualifier("tscDB") DataSource dataSource1) throws Exception {
        SqlSessionFactory sqlSessionFactory = null;
        try {
            SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
            sqlSessionFactoryBean.setTypeAliasesPackage("org.sample.solve.sa.pojo");
            Resource[] mapperLocations = new Resource[] { new ClassPathResource("SASolveMapper.xml") };
            sqlSessionFactoryBean.setMapperLocations(mapperLocations);
            sqlSessionFactoryBean.setDataSource(dataSource1);
            sqlSessionFactory = sqlSessionFactoryBean.getObject();
            sqlSessionFactory.getConfiguration().setMapUnderscoreToCamelCase(true);
            sqlSessionFactory.getConfiguration().setJdbcTypeForNull(JdbcType.NULL);
        }catch(Exception excep) {
            excep.printStackTrace();
            throw new Exception(excep.getMessage());
        }
        return sqlSessionFactory;
    }

    @Bean(name = SQL_SESSION_FACTORY_NAME_2)
    public SqlSessionFactory sqlSessionFactory2(@Qualifier("servicesDB") DataSource dataSource2) throws Exception {
        SqlSessionFactory sqlSessionFactory = null;
        try {
            SqlSessionFactoryBean diSqlSessionFactoryBean = new SqlSessionFactoryBean();
            diSqlSessionFactoryBean.setTypeAliasesPackage("org.sample.solve.sa.pojo");
            Resource[] mapperLocations = new Resource[] {new ClassPathResource("ServicesDBMapper.xml")};
            diSqlSessionFactoryBean.setMapperLocations(mapperLocations);
            diSqlSessionFactoryBean.setDataSource(dataSource2);
            sqlSessionFactory = diSqlSessionFactoryBean.getObject();
            sqlSessionFactory.getConfiguration().setMapUnderscoreToCamelCase(true);
            sqlSessionFactory.getConfiguration().setJdbcTypeForNull(JdbcType.NULL);
        }catch(Exception excep) {
            excep.printStackTrace();
            throw new Exception(excep.getMessage());
        }
        return sqlSessionFactory;
    }

    @Bean
    @Primary
    public MapperScannerConfigurer mapperScannerConfigurer1() {
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        configurer.setBasePackage(MAPPERS_PACKAGE_TSC);
        configurer.setSqlSessionFactoryBeanName(SQL_SESSION_FACTORY_NAME_1);
        return configurer;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer2() {
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        configurer.setBasePackage(MAPPERS_PACKAGE_SERVICES_DB);
        configurer.setSqlSessionFactoryBeanName(SQL_SESSION_FACTORY_NAME_2);
        return configurer;
    }

}

而且我设置使用servlet初始化活动的配置文件。

spring-boot mybatis websphere-8
1个回答
-1
投票

当我试图创建计划任务(在春季启动的应用程序是服务器),我已经注意到了相同的。这项工作并没有启动,直到我通过调用REST服务戳的应用程序或做其他事。不幸的是,我不知道该怎么办,使其工作。

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