因为配置类中url格式中&不用&;在配置文件xml里才用&
正确的:
@Bean(name="ds1")
public DataSource createDataSource(){
try {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("com.mysql.cj.jdbc.Driver");
ds.setJdbcUrl("jdbc:mysql://localhost:3306/myspring?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8");
ds.setUser("root");
ds.setPassword("root");
return ds;
}catch (Exception e){
throw new RuntimeException(e);
}
}