package com.myapp.config;

import net.sf.log4jdbc.sql.jdbcapi.DataSourceSpy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;

import javax.sql.DataSource;

@Configuration
@Profile({"dev", "test"})
public class DatasourceConfig {

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    DataSourceProperties dataSourceProperties;

    @SuppressWarnings("ContextJavaBeanUnresolvedMethodsInspection")
    @Bean(destroyMethod = "close")
    @ConfigurationProperties(prefix = "spring.datasource")
    DataSource realDataSource() {
        return DataSourceBuilder
                .create(this.dataSourceProperties.getClassLoader())
                .url(this.dataSourceProperties.determineUrl())
                .username(this.dataSourceProperties.determineUsername())
                .password(this.dataSourceProperties.determineUsername())
                .build();
    }

    @Bean
    @Primary
    DataSource dataSource() {
        return new DataSourceSpy(realDataSource());
    }
}


@@ -688,59 +688,65 @@
     
-@SuppressWarnings(%22SpringJavaAutowiringInspection%22)
+private final DataSourceProperties dataSourceProperties;%0A
 %0A   
@@ -757,24 +757,48 @@
 towired%0A    
+public DatasourceConfig(
 DataSourcePr
@@ -830,113 +830,86 @@
 ties
-;%0A%0A    @SuppressWarnings(%22ContextJavaBeanUnresolvedMethodsInspection%22)%0A    @Bean(destroyMethod = %22close%22)
+) %7B%0A        this.dataSourceProperties = dataSourceProperties;%0A    %7D%0A%0A    @Bean
 %0A   

refactor datasourceconfig