开发者社区> 问答> 正文

spring-boot executable jar,启动报错:Annotati?报错

spring-boot 构建项目,正常Application在ecilpse中启动没有问题,平时一直war部署也是没有问题的;

最近再尝试打成可执行jar,java -jar xxx.jar 一执行就循环报错,集中在数据库那块;

配置如下:

@Configuration
@EnableTransactionManagement
@MapperScan("com.meix.manage.dao")
public class MybatisConfig implements TransactionManagementConfigurer {

@Bean
public DataSource SimpleDataSource(){
DataSource ds = null;
try{
ds = new SimpleDriverDataSource(new ReplicationDriver(),"jdbc:mysql:replication://127.0.0.1:3326,127.0.0.1:3336/xxx?characterEncoding=utf8","xx","xxx");
System.out.println("---------------"+ds.getConnection().toString()+"--------------");
} catch(SQLException e) {
e.printStackTrace();
}
return ds;
}


@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
Properties myBatisConfig=new Properties();
myBatisConfig.setProperty("logImpl", "SLF4J");
sessionFactory.setConfigurationProperties(myBatisConfig);
sessionFactory.setDataSource(SimpleDataSource());
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactory.setMapperLocations(resolver
.getResources("classpath:/mybatis/*.xml"));
return sessionFactory.getObject();
}

@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new DataSourceTransactionManager(SimpleDataSource());
}

@Bean(destroyMethod="close")
    public SqlSessionTemplate sqlSessionTemplate() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory());
    }

}

错误打印:

13:12:17.375 WARN  o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IUserDao' defined in URL [jar:file:/F:/dev2/workspaces2/ia-manage-parent/ia-manage/target/iamanage.jar!/BOOT-INF/classes!/com/meix/manage/dao/IUserDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/meix/manage/config/MybatisConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SimpleDataSource' defined in class path resource [com/meix/manage/config/MybatisConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceInitializer': Unsatisfied dependency expressed through field 'properties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6d86a830 has not been refreshed yet

展开
收起
爱吃鱼的程序员 2020-06-08 20:02:41 691 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    datasource配置那有问题··具体的还要调试···看日志就没用了·用IntelliJIDEA

    请问您的问题解决了吗

    请问问题解决了吗?

    2020-06-08 20:02:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多