Discuss / Java / @Bean

@Bean

Topic source

MacanRSG

#1 Created at ... [Delete] [Delete and Lock User]
@Bean(name = "dataSource")
public HikariDataSource getDataSource(){
    Properties props = new Properties();    
    props.setProperty("jdbcUrl","jdbc:mysql://localhost:3306/springIoc?characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false");    
    props.setProperty("username","root");    
    props.setProperty("password","1234");    
    HikariConfig config = new HikariConfig(props);    
    config.addDataSourceProperty("cachePrepStmts", "true");    
    HikariDataSource dataSource = new HikariDataSource(config);    
    return dataSource;
}

hhhh

#2 Created at ... [Delete] [Delete and Lock User]

正解👍

赞赞赞,利用函数返回创建第三方bean


  • 1

Reply