TZ_05_Spring_Transaction development of pure notes

1. Database Configuration

jdbcConfiguation.java

 1> Spring EL expression using mating @Value () annotations

 

  @Value("${jdbc.Driver}")
    private String Driver;
    @Value("${jdbc.Url}")
    private String Url;
    @Value("${jdbc.Username}")
    private String Username;
    @Value("${jdbc.Password}")
    private String Password;
  //将该类的返回值以name = "dataSource"注入Spring容器   @Bean(name
= "dataSource") public DataSource dataSource() { DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName(Driver); ds.setUrl (the Url); ds.setUsername (the Username); ds.setPassword (Password); return DS; }

  // the return value to the class name = " the jdbcTemplate " Spring injection container for handling database
    @Bean (name = "the jdbcTemplate")
    public the JdbcTemplate the jdbcTemplate (the DataSource the dataSource) {

        return new new the JdbcTemplate (the dataSource);
    }

 

2.SpringConfiguation.java // similar ApplicationContext.xml

  1> Configuration Notes

// class is specified configuration class 
@Configuration
@ scanning annotation packet @ComponentScan (
"com.hdh" )
// import additional configuration class bytecode manner @Import ({JdbcConfig.
Class , TransactionConfig. Class })
// import jabc.properties file @PropertySource (
"jdbc.properties" ) // open the annotation support @EnableTransactionManagement public class SpringConfiguration { }

 

Guess you like

Origin www.cnblogs.com/asndxj/p/11356326.html