maven仓库之第二篇
- 1. 什么是maven?
- 它是一个软件开发的管理工具,主要管理的工作是:依赖管理,项目构建.
- 2. 使用maven的好处?
- 能够集中管理jar包,提供一键构建.
- 3. maven的安装及配置
- 配置:MAVEN_HOME,PATH路径配置.
- 本地仓库 : <localRepository>
- Settings.xml 文件中.
- <localRepository>d:/repository</..>
- 运行 : mvn -v.
- 4. 常用的maven命令
- compile,test,package,install,deploy
- clean
- site
- 5. maven 工程是具有一定的目录结构
- src
- main
- java(程序主要代码)
- resources(配置文件)
- webapps
- test
- java(测试代码)
- resources(测试的配置文件)
- pom.xml(写一些坐标)
- 6. eclipse工具下的maven工程开发
- 7. 在pom.xml文件中如何引入坐标
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- 8. 总结
- 二、Maven工程的拆分与聚合(重点)
- 一个完整的早期开发好的crm项目,现在要使用maven工程对它进行拆分,这时候就可以将dao拆解出来形成表现独立的工程,同样service,action也都这样拆分
- 工程拆分之后,将来还要聚合(聚合就是将拆分的工程进一步组合在一起,又形成一个完整的项目)
- 为了达到聚合的目标,所以今天会引入
- 父工程(maven project)
- 子模块(maven module) dao ,service, web
- 开发步骤:
- 1.创建一个maven父工程
- 点下一步:
- 创建后的父工程如下:
- 从它的目录结构可以看出,父工程本身不写代码,它里面有一个pom.xml文件,这个文件可以将多个子模块中通用的jar所对应的坐标,集中在父工程中配置,将来的子模块就可以不需要在pom.xml中配置通用jar的坐标了
- 2.如何创建这个父工程的一个子模块?
- 点next,进入如下图:
- 点next,进入如下图:
- 3.再次查看父工程的pom.xml文件
- 4.查看子模块的pom.xml,发现多了一个 parent结点
- 并且内部所包含的结点,其实就是父工程的坐标
- 坐标=groupId+artifactId+version
- 组织名 项目名 版本
- 三.冲突问题的解决
- 1.通过添加<exclusion>标签来解决冲突
- 在父工程中引入了struts-core,hibernate-core,就发现jar包是有冲突的
- Javassist存在版本上冲突问题
- 进入下图:
- 背后的父工程的pom.xml文件中,添加的内容
- 2.依赖调解原则:
- maven自动按照下边的原则调解:
- 1、第一声明者优先原则
- 在pom文件定义依赖,先声明的依赖为准。
- 测试:
- 如果将上边struts-spring-plugins和spring-context顺序颠倒,系统将导入spring-beans-4.2.4。
- 分析:
- 由于spring-context在前边以spring-context依赖的spring-beans-4.2.4为准,所以最终spring-beans-4.2.4添加到了工程中。
- 2、路径近者优先原则
- 例如:A依赖 spirng-beans-4.2.4,A依赖B依赖 spirng-beans-3.0.5,则spring-beans-4.2.4优先被依赖在A中,因为spring-beans-4.2.4相对spirng-beans-3.0.5被A依赖的路径最近。
- 测试:
- 在本工程中的pom中加入spirng-beans-4.2.4的依赖,根据路径近者优先原则,系统将导入spirng-beans-4.2.4:
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>4.2.4.RELEASE</version>
- </dependency>
- 2.使用版本锁定实现冲突解决
- 首先父工程中pom.xml文件添加:
- 在使用坐标时,对于同一个框架,引入多次时,它的版本信息就会多次出现,所以
- 可以借用常量的思想,将这些版本号提取出来,在需要用到的时候,直接写版本的常量名称就可以了。
- 引用上面的常量
- 3.最终在ssh_parent的pom.xml中引入的坐标
- 依赖注入手动排除 : 可以当做特殊情况,struts2框架和hibernate框架很少使用共同的jar包.
- 声明优先原则 : 选择的依据,根据引入顺序,谁先引入,就先使用谁.
- pom.xml里面的Dependencies选项里面的坐标引入的都是直接依赖.
- 而通过直接依赖引入的jar包都是传递依赖.
- 路径近者优先 : 直接引入的依赖,优先级高于传递进来的依赖.
- <!--使用常量来管理以后版本升级的问题 -->
- <properties>
- <spring-version>4.2.4RELEASE</spring-version>
- </properties>
- <!-- 依赖管理节点限制使用jar包的版本 -->
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring-version}</version>
- </dependen
- </dependencies>
- </dependcyManagement>
- 三、依赖关系
- 依赖具有传递性,但不是无限传递的,传递的规则如下:
- A-provided-B B-runtime-C
- 解决方法:
- 如果在依赖传递过程中,导致jar包丢失,我们的做法很简单,就是再导入一次坐标
- 四.编写Service模块
- 1.创建一个maven module项目
- 创建结束后,父工程中结构如下:
- 父工程的pom.xml文件如下
- 2.在service的pom.xml文件中引入dao的jar包
- Web层的子模块创建:
- 四、私服搭建
- 下载nexus
- Nexus 是Maven仓库管理器,通过nexus可以搭建maven仓库,同时nexus还提供强大的仓库管理功能,构件搜索功能等。
- 下载Nexus, 下载地址:http://www.sonatype.org/nexus/archived/
- 下载:nexus-2.12.0-01-bundle.zip
- 安装 :
- 1.解压,进入指定的目录
- 2.安装并启动这个应用程序
- cmd进入bin目录(E:\sshenv\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin),执行nexus.bat install
- 安装成功在服务中查看有nexus服务:
- 卸载nexus
- cmd进入nexus的bin目录,执行:nexus.bat uninstall
- 查看window服务列表nexus已被删除。
- 启动nexus
- 方法1:
- cmd进入bin(你解压的nexus的bin)目录,执行nexus.bat start
- 方法2:
- 直接启动nexus服务
- 查看nexus的配置文件conf/nexus.properties
- # Jetty section
- application-port=8081 # nexus的访问端口配置
- application-host=0.0.0.0 # nexus主机监听配置(不用修改)
- nexus-webapp=${bundleBasedir}/nexus # nexus工程目录
- nexus-webapp-context-path=/nexus # nexus的web访问路径
- # Nexus section
- nexus-work=${bundleBasedir}/../sonatype-work/nexus # nexus仓库目录
- runtime=${bundleBasedir}/nexus/WEB-INF # nexus运行程序目录
- 访问:
- http://localhost:8081/nexus/
- 使用Nexus 内置账户admin/admin123登陆:
- 点击右上角的Log in,输入账号和密码 登陆
- 登陆成功:
- nexus的仓库有4种类型:
- 1.hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
- 2.proxy,代理仓库,用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件。
- 3.group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组。
- 4.virtual(虚拟):兼容Maven1 版本的jar或者插件
- nexus仓库默认在sonatype-work目录中:
- central:代理仓库,代理中央仓库
- apache-snapshots:代理仓库
- 存储snapshots构件,代理地址https://repository.apache.org/snapshots/
- central-m1:virtual类型仓库,兼容Maven1 版本的jar或者插件
- releases:本地仓库,存储releases构件。
- snapshots:本地仓库,存储snapshots构件。
- thirdparty:第三方仓库
- public:仓库组
- 需求 :将ssh_dao的这个工程打成jar包,并放入到私服上去.
- 配置
- 第一步: 需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 。
- 此用户名和密码用于私服校验,因为私服需要知道上传的账号和密码 是否和私服中的账号和密码 一致。
- <server>
- <id>releases</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- <server>
- <id>snapshots</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- releases 连接发布版本项目仓库
- snapshots 连接测试版本项目仓库
- 第二步: 配置项目pom.xml
- 配置私服仓库的地址,本公司的自己的jar包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库
- <distributionManagement>
- <repository>
- <id>releases</id>
- <url>http://localhost:8081/nexus/content/repositories/releases/</url>
- </repository>
- <snapshotRepository>
- <id>snapshots</id>
- <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
- </snapshotRepository>
- </distributionManagement>
- 注意:pom.xml这里<id> 和 settings.xml 配置 <id> 对应!
- 测试
- 将项目dao工程打成jar包发布到私服:
- 1、首先启动nexus
- 2、对dao工程执行deploy命令
- 从私服下载jar包
- 需求
- 没有配置nexus之前,如果本地仓库没有,去中央仓库下载,通常在企业中会在局域网内部署一台私服服务器,有了私服本地项目首先去本地仓库找jar,如果没有找到则连接私服从私服下载jar包,如果私服没有jar包私服同时作为代理服务器从中央仓库下载jar包,这样做的好处是一方面由私服对公司项目的依赖jar包统一管理,一方面提高下载速度,项目连接私服下载jar包的速度要比项目连接中央仓库的速度快的多。
- 本例子测试从私服下载dao 工程jar包。
- 管理仓库组
- nexus中包括很多仓库,hosted中存放的是企业自己发布的jar包及第三方公司的jar包,proxy中存放的是中央仓库的jar,为了方便从私服下载jar包可以将多个仓库组成一个仓库组,每个工程需要连接私服的仓库组下载jar包。
- 打开nexus配置仓库组,如下图:
- 上图中仓库组包括了本地仓库、代理仓库等。
- 在setting.xml中配置仓库
- 在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库。
- <profile>
- <!--profile的id-->
- <id>dev</id>
- <repositories>
- <repository>
- <!--仓库id,repositories可以配置多个仓库,保证id不重复-->
- <id>nexus</id>
- <!--仓库地址,即nexus仓库组的地址-->
- <url>http://localhost:8081/nexus/content/groups/public/</url>
- <!--是否下载releases构件-->
- <releases>
- <enabled>true</enabled>
- </releases>
- <!--是否下载snapshots构件-->
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
- <pluginRepository>
- <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
- <id>public</id>
- <name>Public Repositories</name>
- <url>http://localhost:8081/nexus/content/groups/public/</url>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- 使用profile定义仓库需要激活才可生效。
- <activeProfiles>
- <activeProfile>dev</activeProfile>
- </activeProfiles>
- 配置成功后通过eclipse查看有效pom,有效pom是maven软件最终使用的pom内容,程序员不直接编辑有效pom,打开有效pom
- 有效pom内容如下:
- 下边的pom内容中有两个仓库地址,maven会先从前边的仓库的找,如果找不到jar包再从下边的找,从而就实现了从私服下载jar包。
- <repositories>
- <repository>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- <id>public</id>
- <name>Public Repositories</name>
- <url>http://localhost:8081/nexus/content/groups/public/</url>
- </repository>
- <repository>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <id>central</id>
- <name>Central Repository</name>
- <url>https://repo.maven.apache.org/maven2</url>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>public</id>
- <name>Public Repositories</name>
- <url>http://localhost:8081/nexus/content/groups/public/</url>
- </pluginRepository>
- <pluginRepository>
- <releases>
- <updatePolicy>never</updatePolicy>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <id>central</id>
- <name>Central Repository</name>
- <url>https://repo.maven.apache.org/maven2</url>
- </pluginRepository>
- </pluginRepositories>
- <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>cn.baidu.maven</groupId>
- <artifactId>maven-crm</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>web工程,包括jsp、action等</name>
- <description>web工程,包括jsp、action等</description>
- <!-- 为了确定每个框架的版本号 -->
- <!-- 锁定版本 -->
- <properties>
- <spring.version>4.2.4.RELEASE</spring.version>
- <struts2.version>2.3.24</struts2.version>
- <hibernate.version>5.0.7.Final</hibernate.version>
- <slf4j.version>1.6.6</slf4j.version>
- <log4j.version>1.2.12</log4j.version>
- <shiro.version>1.2.3</shiro.version>
- <cxf.version>3.0.1</cxf.version>
- <c3p0.version>0.9.1.2</c3p0.version>
- <mysql.version>5.1.6</mysql.version>
- </properties>
- <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aspects</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>${hibernate.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-core</artifactId>
- <version>${struts2.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-spring-plugin</artifactId>
- <version>${struts2.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.4</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>1.1.37</version>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.9.1</version>
- </dependency>
- <!-- <dependency>
- <groupId>org.quartz-scheduler</groupId>
- <artifactId>quartz</artifactId>
- <version>2.2.1</version>
- </dependency> -->
- <dependency>
- <groupId>commons-fileupload</groupId>
- <artifactId>commons-fileupload</artifactId>
- <version>1.3.1</version>
- </dependency>
- <!-- jstl -->
- <dependency>
- <groupId>jstl</groupId>
- <artifactId>jstl</artifactId>
- <version>1.2</version>
- </dependency>
- <!-- shiro -->
- <!-- apache shiro dependencies -->
- <!-- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-all</artifactId>
- <version>${shiro.version}</version>
- </dependency> -->
- <!-- spring -->
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.6.8</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <!-- struts2 begin -->
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-core</artifactId>
- <version>${struts2.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>javassist</artifactId>
- <groupId>javassist</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-spring-plugin</artifactId>
- <version>${struts2.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-json-plugin</artifactId>
- <version>${struts2.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-convention-plugin</artifactId>
- <version>${struts2.version}</version>
- </dependency>
- <!-- struts2 end -->
- <!-- hibernate begin -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>${hibernate.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>${hibernate.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>5.2.1.Final</version>
- </dependency>
- <!-- hibernate end -->
- <dependency>
- <groupId>c3p0</groupId>
- <artifactId>c3p0</artifactId>
- <version>${c3p0.version}</version>
- </dependency>
- <!-- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxws</artifactId>
- <version>${cxf.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http</artifactId>
- <version>${cxf.version}</version>
- </dependency> -->
- <!-- log start -->
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${log4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <!-- log end -->
- <!-- Javamail -->
- <!-- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.4.4</version>
- </dependency> -->
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- <!-- <dependency>
- <groupId>org.codehaus.xfire</groupId>
- <artifactId>xfire-core</artifactId>
- <version>1.2.6</version>
- </dependency> -->
- <dependency>
- <groupId>dom4j</groupId>
- <artifactId>dom4j</artifactId>
- <version>1.6</version>
- </dependency>
- <!-- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.11</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml</artifactId>
- <version>3.11</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml-schemas</artifactId>
- <version>3.11</version>
- </dependency> -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
- </dependency>
- <!-- <dependency>
- <groupId>com.oracle</groupId>
- <artifactId>ojdbc14</artifactId>
- <version>10.2.0.4.0</version>
- </dependency> -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
- <version>2.6.6</version>
- </dependency>
- </dependencies>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <encoding>UTF-8</encoding>
- <showWarnings>true</showWarnings>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <!-- parnet节点指定子模块的 父工程的坐标信息 -->
- <parent>
- <groupId>cn.baidu</groupId>
- <artifactId>ssh_maven</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <artifactId>ssh_dao</artifactId>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.10</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <!-- 上传jar包使用命令 deploey部署到私服 后本地仓库会不会有 -->
- <distributionManagement>
- <repository>
- <id>releases</id>
- <url>http://localhost:8081/nexus/content/repositories/releases/</url>
- </repository>
- <snapshotRepository>
- <id>snapshots</id>
- <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
- </snapshotRepository>
- </distributionManagement>
- </project>
- applicationContext-dao.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:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
- <!-- dataSource数据源 -->
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
- <property name="jdbcUrl" value="jdbc:mysql:///maven_ssh"></property>
- <property name="user" value="root"></property>
- <property name="password" value="root"></property>
- </bean>
- <!-- seesionFactory -->
- <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <!-- 数据源 -->
- <property name="dataSource" ref="dataSource"></property>
- <!-- hibernate的配置 --><!-- 实体类映射 -->
- <property name="configLocations" value="classpath:hibernate.cfg.xml"></property>
- </bean>
- <!-- 事务的管理器 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- <!-- 事务的通知 -->
- <tx:advice id="txAdvice" >
- <tx:attributes>
- <tx:method name="save*" propagation="REQUIRED"/>
- <tx:method name="update*" propagation="REQUIRED"/>
- <tx:method name="delete*" propagation="REQUIRED"/>
- <tx:method name="find*" read-only="true"/>
- </tx:attributes>
- </tx:advice>
- <!-- 切面配置 -->
- <aop:config>
- <!-- 切入点配置 -->
- <aop:pointcut expression="execution(* cn.baidu.service.*.*(..))" id="pointcut"/>
- <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
- </aop:config>
- <!-- 自己的持久层dao -->
- <bean id="customerDao" class="cn.baidu.dao.impl.CustomerDaoImpl">
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- </beans>
maven仓库之第二篇的更多相关文章
- maven仓库之第一篇
maven jar仓库 :存放maven项目使用的jar包. 中央仓库,存放99%免费开源项目jar包,apache公司负责维护的,以T为单位的存储. 例如 : struts2-core-2.3.24 ...
- 【第六篇】- Maven 仓库之Spring Cloud直播商城 b2b2c电子商务技术总结
Maven 仓库 在 Maven 的术语中,仓库是一个位置(place). Maven 仓库是项目中依赖的第三方库,这个库所在的位置叫做仓库. 在 Maven 中,任何一个依赖.插件或者项目构建的输出 ...
- 【第二篇】- Maven 环境配置之Spring Cloud直播商城 b2b2c电子商务技术总结
Maven 环境配置 Maven 是一个基于 Java 的工具,所以要做的第一件事情就是安装 JDK. 如果你还未安装 JDK,可以参考我们的 Java 开发环境配置. 系统要求 项目 要求 JDK ...
- 拥抱 Android Studio 之四:Maven 仓库使用与私有仓库搭建
使用.创造和分享 笔者曾经不思量力的思考过『是什么推动了互联网技术的快速发展?』这种伟大的命题.结论是,除了摩尔定律之外,技术经验的快速积累和广泛分享,也是重要的原因. 有人戏称,『写 Java,首先 ...
- N使用exus2打造企业maven仓库(三)
假设项目中,我没有使用maven,我应该做出选择,或为项目.或者用它来推动这个项目从maven.有人会问,为什么maven?无需maven我们没有很好的操作. 这里,只说两件事情我最欣赏:第一点是管理 ...
- Android studio Maven仓库使用
原文:How to distribute your own Android library through jCenter and Maven Central from Android Studio ...
- Maven系列第8篇:你的maven项目构建太慢了,我实在看不下去,带你一起磨刀!!多数使用maven的人都经常想要的一种功能,但是大多数人都不知道如何使用!!!
maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第8篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...
- maven仓库私服配置
私服访问地址:[[http://192.168.1.252:9080/nexus/content/groups/public/ 地址]] 1. 打开eclipse/myeclipse的maven插件: ...
- RabbitMQ学习总结 第二篇:快速入门HelloWorld
目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...
随机推荐
- 学习Python编程技术的流程与步骤,自学与参加培训学习都适用
一.清楚学习目标 无论是学习什么知识,都要有一个对学习目标的清楚认识.只有这样才能朝着目标持续前进,少走弯路,从学习中得到不断的提升,享受python学习计划的过程. 虽然目前的编程语言有很多,但是 ...
- 《大话设计模式》——简单工厂模式(Python版)
简单工厂模式(Simple Factory Pattern):是通过专门定义一个类来负责创建其他类的实例,被创建的实例通常都具有共同的父类. 例: 使用Python设计一个控制台计算器,要求输入两个数 ...
- HttpRunner学习4--使用正则表达式提取数据
前言 在HttpRunner中,我们可通过extract提取数据,当响应结果为 JSON 结构,可使用 content 结合 . 运算符的方式,如 content.code,用起来十分方便,但如果响应 ...
- 【后端C#】后台通过http post 调用 webservice 的方法
定义http post 调用webservice的某个方法 /// <summary> /// http Post调用 WebService /// </summary> pu ...
- Android 再次打开APP进入按Home键退出时的界面(thisTaskRoot)
问题 Android 设置页面的启动模式为 singletask 之后,当按Home 退出时,再重新打开应用,还会进入首启动页.就会造成一些应用需要重新登录,当前页数据丢失等问题 解决 去除启动页的 ...
- linux 定时备份数据库
说明 检查Crontab是否安装 若没有 需要先安装Crontab定时工具 安装定时工具参考(https://www.cnblogs.com/shaohuixia/p/5577738.html) 需要 ...
- h5 Video打开本地摄像头和离开页面关闭摄像头
<div> <video id="video" style="width=100%; height=100%; object-fit: fill&quo ...
- Java之封装与访问权限控制(一)
目录 Java之封装与访问权限控制(一) 封装的概念 访问控制符 属性私有化 Java之封装与访问权限控制(一) 对于封装的概念,我总觉得自己还是挺了解的,但是真要我说,还真说不出个啥来.我只能默默地 ...
- 设置tomcat为自动启动
第一步:设置tomcat为服务启动项 进入dos窗口,输入service.bat install,启动服务, 这里要注意的是,如果直接在cmd输入报错,需要你进入到tomcat的目录下执行cmd 第二 ...
- Python中Pyyaml模块的使用
一.YAML是什么 YAML是专门用来写配置文件的语言,远比JSON格式方便. YAML语言的设计目标,就是方便人类读写. YAML是一种比XML和JSON更轻的文件格式,也更简单更强大,它可以通过缩 ...