【参考】:maven pom.xml加载不同properties配置[转]

首先 看看效果:

点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项。默认勾选localhost。localhost对应项目启动后,会加载配置左侧localhost文件夹下面的jdbc.perperties 和 redis.properties。 对于项目中存在测试数据库或者运行数据库的区分的时候 我们可以通过勾选快速切换。那么我们是如何实现的呢

一:在左侧文件目录项目 配置相对于的文件目录,并且注释掉你之前的加载 ,如图所示,

配置好所需的jdbc 链接   需要注意的 (正确写法)url=jdbc:mysql://127.0.0.1:3306/course_design?useUnicode=true&characterEncoding=UTF-8 中间的间隔符 必须用 & 替换掉之前写的 (错误写法)url=jdbc:mysql://127.0.0.1:3306/course_design?useUnicode=true&characterEncoding=UTF-8

具体原因参考   Caused by: org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 84; 对实体 "characterEncoding"

                                        

二:配置 pom.xml

 <!--配置profiles-->
<profiles>
<profile>
<id>localhost</id>
<!--默认勾选设置-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>localhost</env>
</properties>
</profile> <profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>master</id>
<properties>
<env>master</env>
</properties>
</profile>
</profiles> <build>
......................................
</build>
<build>
.............................
<!--指定待加载的文件位置-->
<filters>
<filter>configs/${env}/jdbc.properties</filter>
<filter>configs/${env}/redis.properties</filter>
</filters> <!--指定需要这些加载数据的 配置文件位置-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
<filtering>true</filtering>
</resource>
</resources> </build>

理论上 这个时候 以及在pom,xml中 配置完成了 点击编译之后 如果 正常是可以的

但我这里报错了  3 字节的 UTF-8 序列的字节 3 无效后来查询资料 发现还需要配置一个utf-8编译 【参考】http://blog.csdn.net/lzupb/article/details/53008481

<!-- resource插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

其实后来 还有一个问题 就是

  1. : Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  2. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 30 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 84; 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。  这样的的一个异常

这个时候 前面介绍的jdbc url写法就解决了  把&  变成 &amp; 就好了

在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样的更多相关文章

  1. Dll的编写 在unity中加载

    1. 在VS中新建Dll项目 2.在头文件中对函数进行声明 extern "C" int _declspec(dllexport) testunity(); 3.在源文件中写函数体 ...

  2. Spring中加载xml配置文件的六种方式

    Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog  因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...

  3. Spring中加载ApplicationContext.xml文件的方式

    Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...

  4. web.xml文件中加载顺序的优先级

    在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...

  5. DirectUI界面编程(三)从XML文件中加载界面

    Duilib支持xml界面布局,使得界面设计与逻辑处理相分离,本节介绍如何从xml文件中加载界面元素. 我们需要以下几个步骤: 创建并初始化CPaintManagerUI对象. 创建CDialogBu ...

  6. web.xml的加载过程配置详解

      一:web.xml加载过程 简单说一下,web.xml的加载过程.当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有 ...

  7. web.xml文件加载顺序

    1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...

  8. 史上最全的maven pom.xml文件教程详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. web.xml 的加载过程

    初始化过程: 在启动Web项目时,容器(比如Tomcat)会读web.xml配置文件中的两个节点<listener>和<contex-param>. 接着容器会创建一个Serv ...

随机推荐

  1. git操作常用命令

    一.使用git 1.git是什么? Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己 ...

  2. noi.ac#309 Mas的童年(子集乱搞)

    题意 题目链接 Sol 记\(s_i\)表示前\(i\)个数的前缀异或和,我们每次相当于要找一个\(j\)满足\(0 < j < i\)且\((s_i \oplus s_j) + s_j\ ...

  3. Ocelot + Consul + Registrator 基于Docker 实现服务发现、服务自动注册

    目录 1. Consul集群搭建 1.1 F&Q Consul官方推荐的host网络模式运行 2. Registrator服务注册工具 2.1 F&Q Registrator悬挂服务 ...

  4. 服务器四:多进程epoll

    #include <fcntl.h> #include <sys/socket.h> #include <netinet/in.h> #include <ar ...

  5. Debain/Ubuntu/Deepin 下使用 ss

    如果你有一台 ss 的服务器,在 Debian Like 的环境下要如何***呢? 安装 ss 客户端 如果还没安装 pip 就得先安装 sudo apt-get install python-pip ...

  6. 城市经纬度 json

    [ { "name": "北京市", "log": "116.46", "lat": "3 ...

  7. 初步了解PE分析

    尝试编写代码获取PE文件的信息. 首先使用 CreateFile打开一个PE文件并返回一个用于访问该对象的handle. HANDLE CreateFile( LPCTSTR lpFileName, ...

  8. 如何使用java validation api进行参数校验----Hibernate-Validation

    在日常开发中,Hibernate Validator经常用来验证bean的字段,基于注解,方便快捷高效. 1. Bean Validation 中内置的 constraint 注解           ...

  9. java网络爬虫基础学习(三)

    尝试直接请求URL获取资源 豆瓣电影 https://movie.douban.com/explore#!type=movie&tag=%E7%83%AD%E9%97%A8&sort= ...

  10. bilibili弹幕爬取

    随便进入一个视频页面,打开开发者工具,清空network空间,进入XHR,刷新抓包. 双击查看弹幕