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

how to add another datasource #4

Open
zhangweilun opened this issue Dec 17, 2016 · 4 comments
Open

how to add another datasource #4

zhangweilun opened this issue Dec 17, 2016 · 4 comments

Comments

@zhangweilun
Copy link

i want to use springboot and Ebean,and i have two datasource, how to do it

@zhangweilun
Copy link
Author

please help me , i like ebean

@rbygrave
Copy link
Contributor

The best place to get help is on the google group - https://groups.google.com/forum/#!forum/ebean
That has more people reading / watching ... more people to help.

For this question you will need to outline what you are doing (if you are using the Ebean singleton and properties mechanism or a FactoryBean or other mechanism) and what you are trying to achieve (what is the use case for the multiple EbeanServer instances). Thanks, Rob.

@wangli-it
Copy link

I want to konw ,this project is only support h2 ?
this is my mysql config:
datasource.db.username=root
datasource.db.password=root
datasource.db.databaseUrl=jdbc:mysql://127.0.0.1:3306/pos
datasource.db.databaseDriver=com.mysql.jdbc.Driver
datasource.db.platform= mysql
please tell me why springboot start with the error
the error is : Caused by: java.lang.RuntimeException: DataSource user is null?
please help me , i like ebean

@azwar
Copy link

azwar commented Sep 30, 2020

@wangli-it and @zhangweilun you can create two object of EbeanServer with it's own data source, here I have the sample for you:


  private EbeanServer createH2EbeanServer() {
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setName("h2");

        DataSourceConfig config = new DataSourceConfig();
        config.setDriver("org.h2.Driver");
        config.setUrl("jdbc:h2:tcp://localhost/~/Development/database/h2/adaberita4;AUTO_RECONNECT=FALSE");
        config.setUsername("yourh2username");
        config.setPassword("yourh2password");
        serverConfig.setDdlGenerate(false);
        serverConfig.setDdlRun(false);

        serverConfig.setDefaultServer(false);
        serverConfig.setRegister(false);
        serverConfig.addPackage("com.example.yourproject.entity");
        serverConfig.setDataSourceConfig(config);

        return EbeanServerFactory.create(serverConfig);
    }

    private EbeanServer createMySqlEbeanServer() {
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setName("mysql");

        DataSourceConfig config = new DataSourceConfig();
        config.setDriver("com.mysql.cj.jdbc.Driver");
        config.setUrl("jdbc:mysql://localhost/adaberita?useTimezone=true&serverTimezone=GMT%2B7");
        config.setUsername("yourusername");
        config.setPassword("yourpassword");

        serverConfig.setDdlGenerate(true);
        serverConfig.setDdlRun(false);
        serverConfig.setDefaultServer(false);
        serverConfig.setRegister(false);
        serverConfig.addPackage("com.example.yourproject.entity");
        serverConfig.setDataSourceConfig(config);

        return EbeanServerFactory.create(serverConfig);
    }

There are two methods that return EbeanServer with different datasource. Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants