@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ScopeBean {
}

@Profile @Scope

 

@Profile @Scope

 

@Bean(name = "dataSource")
@Profile("dev")
public DataSource getDevDataSource () {
    Properties props = new Properties();
    props.setProperty("driver", "com.mysql.jdbc.Driver");
    props.setProperty("url", "jdbc:mysql://localhost:3306/dev_spring_boot");
    props.setProperty("username", "root");
    props.setProperty("password", "222");
    DataSource dataSource = null;
    try {
        dataSource = BasicDataSourceFactory.createDataSource(props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dataSource;
}

@Bean(name = "dataSource")
@Profile("test")
public DataSource getTestDataSource () {
    Properties props = new Properties();
    props.setProperty("driver", "com.mysql.jdbc.Driver");
    props.setProperty("url", "jdbc:mysql://localhost:3306/test_spring_boot");
    props.setProperty("username", "root");
    props.setProperty("password", "222");
    DataSource dataSource = null;
    try {
        dataSource = BasicDataSourceFactory.createDataSource(props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dataSource;
}

相关文章:

  • 2021-05-21
  • 2022-12-23
  • 2021-05-12
  • 2021-07-21
  • 2021-11-19
  • 2022-02-04
  • 2021-09-16
  • 2021-06-24
猜你喜欢
  • 2021-06-15
  • 2022-01-28
  • 2021-12-01
  • 2021-09-19
  • 2021-12-15
  • 2021-04-13
  • 2021-12-16
相关资源
相似解决方案