Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整合springboot报错哎, The connectionFactory cannot be null #29

Closed
BruceLvLvXin opened this issue Nov 14, 2020 · 4 comments
Closed
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@BruceLvLvXin
Copy link

2020-11-14 17:11:09.963 WARN 7360 --- [nio-8080-exec-6] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: java.lang.IllegalStateException: The connectionFactory cannot be null
这个错啥意思?不懂了

@catchex
Copy link
Member

catchex commented Nov 14, 2020

1)首先提问题要仔细,日志信息需要以代码的形式包裹前后用 "```" 包裹,
2)“ The connectionFactory cannot be null” 你可以参考:http://www.objsql.com/docs/basic/demo-source/ 这里的说明

完整的代码参考:Application.java

private class ApplicationConnectionFactory implements ConnectionFactory {

    private final ApplicationContext applicationContext;

    public ApplicationConnectionFactory(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public Connection getConnection(String dataSourceName) throws SQLException {
        DataSource dataSource = (DataSource) applicationContext.getBean(dataSourceName);
        return dataSource.getConnection();
    }
}
@Bean(name = ConnectionFactory.DEFAULT_DATA_SOURCE_NAME)
@ConfigurationProperties("spring.objsql-datasource.objsql-default-datasource")
public DataSource getDataSource(){
    return DataSourceBuilder.create().build();
}

@EventListener
public void onApplicationEvent(ApplicationStartedEvent event) {
    ConnectionFactory connectionFactory = new ApplicationConnectionFactory(event.getApplicationContext());
    SQLExecutor sqlExecutor = new CacheableSQLExecutor();
    LoggerFactory loggerFactory = new ObjLoggerFactoryImpl();

    Databases.installConnectionFactory(connectionFactory);
    Databases.installSqlExecutor(sqlExecutor);
    Databases.installLoggerFactory(loggerFactory);
}

@catchex
Copy link
Member

catchex commented Nov 14, 2020

ObjectiveSQL 全局注入你可以参考一下Databases.java 和Tables.java

@catchex
Copy link
Member

catchex commented Nov 15, 2020

如果已经修复了,请关闭issue ,如果还有疑问请回复。

@catchex catchex added the question Further information is requested label Nov 15, 2020
@catchex
Copy link
Member

catchex commented Nov 16, 2020

我应该扩展一下SpringBoot, 实现AutoConfiguration,过两天会1.3.8 版本,会修复该问题。

@catchex catchex self-assigned this Nov 16, 2020
@catchex catchex added enhancement New feature or request good first issue Good for newcomers and removed question Further information is requested labels Nov 16, 2020
@catchex catchex added this to the 1.3.8 milestone Nov 16, 2020
@catchex catchex closed this as completed Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants