zoukankan      html  css  js  c++  java
  • 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样

    【参考】: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; 就好了

  • 相关阅读:
    Jquery、Ajax实现新闻列表页分页功能
    html中文字溢出处理(text-overflow)
    canvas图像绘制过程中的注意
    问题账户需求分析
    2016年秋季个人阅读计划
    阅读笔记之我们应当怎样做需求分析
    软件工程课个人总结
    人月神话阅读笔记—第四章
    人月神话阅读笔记—第三章
    人月神话阅读笔记—序言及第一、二章
  • 原文地址:https://www.cnblogs.com/luffyu/p/6646110.html
Copyright © 2011-2022 走看看