1 maven 的pom文件查用标签,多模块maven项目,spring常用注解

<dependencies></dependencies>  此标签是包含多个项目依赖的<dependency></dependency>

dependency 标签:

<dependency></dependency> 内部通过groupid ,artifactId,version确定唯一的依赖,有人称这三个为坐标

groupId:组织的唯一标识

artifactId:项目的唯一标识

version:项目的版本

例如:

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
</dependency>

变量的定义<properties></properties> 可以定义变量,并在dependency中引用:

定义:

<properties>

    <springfox.version>2.4.0</springfox.version>

</properties>

 

引用是,${中间是标签的内容}

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${springfox.version}</version>
</dependency>

编译配置

<build>
    <plugins>
        <!-- sonar单元测试jia包 -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <formats>
                    <format>xml</format>
                </formats>
            </configuration>
        </plugin>
    </plugins>
</build>

定义;

<profile>
    <id>development</id>
    <properties>
        <project.profile>development</project.profile>
    </properties>
</profile>
<profile>
    <id>production</id>
    <properties>
        <project.profile>product</project.profile>
    </properties>
</profile>
<profile>
    <id>test</id>
    <properties>
        <project.profile>test</project.profile>
    </properties>
</profile>

 

打包时指定配置文件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <quiet>true</quiet>
                <files>
                    <file>${user.dir}/config/${project.profile}.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

创建多模块maven项目:

创建好maven项目之后,根据需要创建不通的 模块;

 

 

在此创建了 6个模块:

创建的6个模块会再 最外层的pom文件中自动 定义为module;

每个模块直接需要引用时 ,需要在 对应模块的 pom中修改 增加需要引用的模板即可;
例如 dao依赖 beans;在dao的pom中增加:artifactId 就是 最外层pom中定义的module值;

 

 

spring基础配置:

四个原则:

使用pojo进行轻量级和最小侵入式开发;

通过依赖注入和基于接口编程实现松耦合;

通过aop和默认习惯进行声明式编程

使用aop和模板减少模式化代码

控制反转 inversion of control  IOC

依赖注入 dependency ingection   DI

控制反转是通过依赖注入实现的

依赖注入就是指的容器扶着创建对象和维护对象间的依赖关系,而不是通过对象本身负责自己的创建和解决自己的依赖;

依赖注入的主要目的是为了解耦;

spring ioc容器 负责创建bean;并通过容器将功能类bean注入到需要的bean中;

 

声明bean的注解:

@Component 组件,没有明确的角色

@Service 在业务逻辑层service层的 类使用;

@Repository 在数据访问层dao使用

@Controller在展示层,web层使用;

上面四个注解是等效的;

@Configuration 声明当前类是一个配置类,相当于一个spring配置的xml文件;

@Bean  注解在方法上,声明当前方法返回值为一个bean;

@ComponentScan("需要扫描的包") 会扫描此包及子级包下所有需要注册的bean

AOP面向切面编程:

@Aspect  声明是一个切面

@After  @Before @ Around  定义建言(davice) 可直接将拦截规则(切点)作为参数;

@Target(ElementType.MEHTOD)  定义切点可以使用在方法上,或其他选择;

 

@Retention(RetentionPolicy.RUNTIME)  运行时有效;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值