Spring的Bean的xml配置

Spring的applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context.xsd">
                        
   

<!--  引入jdbc.properties -->
   
<!--     
    组件扫描器:
        @Controller
        @Service
        @Repository
        @Component
        @Autowired
        
     @Controller  @Service  @Repository   @Component  只要你的类上面加了此注解
     就证明你这个类交给了spring进行管理控制
     
     其实我们看了源码发现 @Controller  @Service  @Repository   @Component源码是一样的,
     其实他们是一种标志,控制层我们打@Controller   业务层打@Service   持久层打@Repository
     除开以上三层 其他类如果要使用注解的方式交给spring管理,我们就使用@Component这样打注解才是规范
        
  -->

连接地址池配置数据库的数据


 <context:property-placeholder location="classpath:jdbc.properties"/>
    <!-- dataSource===jdbc.properties -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
    </bean>  
    

发布了17 篇原创文章 · 获赞 1 · 访问量 182

猜你喜欢

转载自blog.csdn.net/weixin_43404554/article/details/105166173