Enhanced java beans

Builder๋ฅผ ์ง€์›ํ•ด์ฃผ์ง€ ์•Š๊ฑฐ๋‚˜, ๊ตฌ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์ข…์ข… ๋งˆ์ฃผ์น˜๊ฒŒ ๋˜์–ด ์ฝ”๋“œ๋ฅผ ์ง€์ €๋ถ„ ํ•˜๊ฒŒํ•˜๋Š” ์ž๋ฐ” ๋นˆ์ฆˆ ํŒจํ„ด์„ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์‹์ด๋‹ค.

Before

    @Bean
    public DataSource dataSource(){
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(DriverClass);
        dataSource.setPassword(password);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        return dataSource;
    }

after

    @Bean
    public DataSource dataSource(){
        return new DriverManagerDataSource(){{
            setDriverClassName(DriverClass);
            setPassword(password);
            setUrl(url);
            setUsername(username);
        }};
    }

Last updated