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
datasource配置那有问题··具体的还要调试···看日志就没用了·用IntelliJIDEA
请问您的问题解决了吗
请问问题解决了吗?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。