Springxml配置文件中引入properties文件

在xml文件中引入properties文件,注入到bean中

xml文件

<beans>
   <!-- enable processing of annotations such as @Autowired and @Configuration -->
   <context:annotation-config/>
   <context:property-placeholder location="classpath:/com/acme/jdbc.properties"/>
<!-- 这个配置 开启引入properties文件 -->
   
   <bean class="com.acme.AppConfig"/>

   <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
       <property name="url" value="${jdbc.url}"/>
       <property name="username" value="${jdbc.username}"/>
       <property name="password" value="${jdbc.password}"/>
   </bean>
</beans>

 

properties文件

user=root
password=root
url=jdbc:mysql://127.0.0.1:3306/ydlclass?characterEncoding=utf8&serverTimezone=Asia/Shanghai
driverName=com.mysql.cj.jdbc.Driver

 

posted @ 2022-03-15 21:29  子非鱼!  阅读(548)  评论(0编辑  收藏  举报