Spring项目XML文件使用小结

 更新时间:2022年07月18日 09:38:57   作者:amcomputer  
这篇文章主要介绍了Spring项目XML文件使用常见介绍,主要包括项目pom文件,项目初始IOC容器及项目需要自动装配的代码详解,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下

1 项目pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yang</groupId>
    <artifactId>spring-study</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>spring-01-ioc1</module>
        <module>spring-02-hellpspring</module>
        <module>spring-04-di</module>
        <module>spring-06-autowired</module>
        <module>spring-07-annotation</module>
    </modules>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.4.RELEASE</version>
        </dependency>
    </dependencies>

</project>
···

2 项目初始IOC容器

```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd">
    <!-- more bean definitions go here -->
</beans>
···

3 项目需要自动装配

```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd">
    <context:annotation-config/>
    <bean id="dog" class="com.yang.pojo.Dog"></bean>
    <bean id="cat" class="com.yang.pojo.Cat"></bean>
    <bean id = "people" class="com.yang.pojo.People">
          <property name="cat" ref="cat"/>
        <property name="dog" ref="dog"/>
        <property name="name" value="张3"/>
    </bean>
</beans>

增加的点:
1 xmlns:context="http://www.springframework.org/schema/context"等等头文件

2 context:annotation-config/

4 项目需要注解

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
       https://www.springframework.org/schema/aop/spring-aop.xsd">
<!--    指定要扫描的包,包下面的注解才能够生效-->
<context:component-scan base-package="com.yang.pojo"/>
<!--    注解驱动-->
    <context:annotation-config/>
</beans>

增加的点:

<context:component-scan base-package=“com.yang.pojo”/>

https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop

到此这篇关于Spring项目XML文件使用常见介绍的文章就介绍到这了,更多相关Spring项目XML文件使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Mybatis中如何设置sqlSession自动提交

    Mybatis中如何设置sqlSession自动提交

    在MyBatis中,默认情况下,获取的SqlSession对象不会自动提交事务,这意味着在进行更新、删除或插入等操作后,需要显式调用commit方法来提交事务,但是,可以在获取SqlSession时通过将openSession方法的参数设置为true
    2024-09-09
  • MyBatis全局配置文件详解

    MyBatis全局配置文件详解

    这篇文章主要介绍了mybatis 加载配置文件的方法,通过实例代码给大家介绍了mybatis 加载配置文件的两种方式,需要的朋友可以参考下
    2021-07-07
  • OpenFeign调用服务请求头丢失Token的解决

    OpenFeign调用服务请求头丢失Token的解决

    这篇文章主要介绍了OpenFeign调用服务请求头丢失Token的解决方法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-06-06
  • Spring Boot 数据校验@Valid+统一异常处理的实现

    Spring Boot 数据校验@Valid+统一异常处理的实现

    这篇文章主要介绍了Spring Boot 数据校验@Valid+统一异常处理的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04
  • Mybatis中foreach的使用详解

    Mybatis中foreach的使用详解

    Mybatis中foreach标签的使用详解,包括属性说明、代码示例和总结,感兴趣的朋友跟随小编一起看看吧
    2024-11-11
  • Springboot打包成jar发布的操作方法

    Springboot打包成jar发布的操作方法

    打包的方式有打包成jar包或者打包成war包发布,区别在于jar包内置了tomcat、netty等服务器,更改只需要修改pom.xml的坐标即可,war不内置服务器,需要上传到服务器tomcat解压后运行,本文分析Springboot打包成jar发布,感兴趣的朋友一起看看吧
    2023-02-02
  • SpringBoot整合FastDFS中间件实现文件分布管理

    SpringBoot整合FastDFS中间件实现文件分布管理

    FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件上传、文件下载等,解决了大容量存储和负载均衡的问题,本文介绍了SpringBoot整合FastDFS中间件实现文件分布管理,需要的朋友可以参考下
    2024-08-08
  • java线程阻塞中断与LockSupport使用介绍

    java线程阻塞中断与LockSupport使用介绍

    本文将详细介绍java线程阻塞中断和LockSupport的使用,需要了解更多的朋友可以参考下
    2012-12-12
  • 带你了解Java数据结构和算法之无权无向图

    带你了解Java数据结构和算法之无权无向图

    这篇文章主要为大家介绍了Java数据结构和算法之无权无向图 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
    2022-01-01
  • Spring集成MyBatis 及Aop分页的实现代码

    Spring集成MyBatis 及Aop分页的实现代码

    这篇文章主要介绍了Spring集成MyBatis 及Aop分页的实现,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04

最新评论