Spring-常用依赖及配置

丨Fanny丨Cri 2020-03-01

##常用依赖```xml<dependencies>        <dependency>            <groupId>org.mybatis</groupId>            <artifactId>mybatis</artifactId>            <version>3.4.5</version>        </dependency>        <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>8.0.15</version>        </dependency>        <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>4.12</version>        </dependency>        <dependency>            <groupId>log4j</groupId>            <artifactId>log4j</artifactId>            <version>1.2.17</version>        </dependency>        <dependency>            <groupId>commons-beanutils</groupId>            <artifactId>commons-beanutils</artifactId>            <version>1.9.2</version>        </dependency>        <dependency>            <groupId>javax.activation</groupId>            <artifactId>activation</artifactId>            <version>1.1</version>        </dependency>        <dependency>            <groupId>org.projectlombok</groupId>            <artifactId>lombok</artifactId>            <version>1.18.8</version>            <scope>provided</scope>        </dependency>        <dependency>            <groupId>org.springframework</groupId>            <artifactId>spring-webmvc</artifactId>            <version>5.1.10.RELEASE</version>        </dependency>         <dependency>                    <groupId>org.aspectj</groupId>                    <artifactId>aspectjweaver</artifactId>                    <version>1.9.1</version>         </dependency>    </dependencies>```##注解说明    - 都是用来自动装箱的,都可以放在属性字段上    - 如果类型和名字都找不到的情况下,就会报错    - @Autowired :自动装箱通过类型,名字【区别:有提示信息】【常用】        如果Autowired不能唯一自动装配上属性,则需要通过@Qualifier(value="xxx")    - @Nullable:字段标记了这个注解,说明这个字段可以为null    - @Resource : 自动装配通过名字,类型【区别:没有提示信息】##Spring常用配置```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:p="http://www.springframework.org/schema/p"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">        <context:component-scan base-package="cn.scitc.pojo"></context:component-scan>        <bean id="cat" class="cn.scitc.pojo.cat"/>        <bean id="dog" class="cn.scitc.pojo.dog"/>        <!--<bean id="cat11" class="cn.scitc.pojo.cat"/>-->        <!--<bean id="dog11" class="cn.scitc.pojo.dog"/>-->        <bean id="person" class="cn.scitc.pojo.person"/></beans>```

相关推荐