创建一个xml文件,添加坐标
<bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/one"></property>
<property name="username" value="root"></property>
<property name="password" value="admin123"></property>
</bean>
代码自动创建数据源
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ApplicationContext.xml");
DruidDataSource druidDataSource = (DruidDataSource) applicationContext.getBean("druidDataSource");
Connection connection = druidDataSource.getConnection();
System.out.println(connection);
connection.close();