maven项目引入spring boot依赖之后filter不生效的问题
来源:互联网 发布:为什么445端口关不掉 编辑:程序博客网 时间:2024/06/13 06:35
创建一个maven项目,项目结构如下:
其中,pom.xml的内容如下:
<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>com.pp.test</groupId><artifactId>properties-test</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>properties-test</name><url>http://maven.apache.org</url><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies><build><filters><filter>src/main/profiles/profile-${profiles.active}.properties</filter></filters><resources><resource><filtering>true</filtering><directory>src/main/resources</directory></resource></resources></build><profiles><profile><id>dev</id><properties><profiles.active>dev</profiles.active></properties><activation><activeByDefault>true</activeByDefault></activation></profile><profile><id>test</id><properties><profiles.active>test</profiles.active></properties></profile><profile><id>prod</id><properties><profiles.active>prod</profiles.active></properties></profile></profiles></project>
application.properties 文件内容:
jdbc.driverClassName=${jdbc.driverClassName}jdbc.url=${jdbc.url}jdbc.username=${jdbc.username}jdbc.password=${jdbc.password}
profile-dev.properties 文件内容:
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql:///db_usersjdbc.username=rootjdbc.password=root
启动应用,报错了,错误如下:
Caused by: java.lang.IllegalArgumentException: Circular placeholder reference 'jdbc.url' in property definitionsat org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:141) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:162) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:227) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:61) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:527) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:132) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:129) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:81) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.PropertySourcesPropertyResolver.getPropertyAsRawString(PropertySourcesPropertyResolver.java:71) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:239) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:147) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:831) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]... 17 common frames omitted
报这个错误的原因是,maven的filtering没有起作用,没有把占位符给替换掉。(大家可以执行mvn clean package,看看打包后的jar里面的application.properties文件,是否有替换占位符)
filtering无效的原因是,pom.xml继承了spring boot的依赖
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent>
点开这个依赖的pom.xml,我们发现
spring boot把默认的占位符号${}改成了@
找到原因了,那怎么解决就很简单了。
方法一:
在pom.xml里面添加如下内容
<properties><resource.delimiter>${}</resource.delimiter></properties>
方法二:
application.properties里面不用${},改成@
jdbc.driverClassName=@jdbc.driverClassName@jdbc.url=@jdbc.url@jdbc.username=@jdbc.username@jdbc.password=@jdbc.password@
方法三:
pom.xml不继承spring-boot-starter-parent,dependency里面配置全部的依赖和版本号(继承了之后,很多依赖不用写version)
方法四:
把
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent>改成
<dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>1.5.9.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
阅读全文
0 0
- maven项目引入spring boot依赖之后filter不生效的问题
- 项目中引入 Spring AOP 但不生效的解决方法
- maven依赖不生效
- 面试问题项目已经依赖了一个parent,怎么引入spring boot依赖
- spring boot 基本依赖引入
- spring boot创建项目包依赖问题
- 在spring boot项目(maven)中引入其他 spring boot项目(jar)
- spring boot spring.config.name 不生效
- 新建一个maven spring boot项目中遇到的问题
- spring boot项目依赖spring mvc项目注入失败问题
- Gradle 依赖最新版本不生效的问题
- Spring boot maven项目配置文件覆盖问题
- Spring boot Maven 打包引入本地的jar包
- eclipse 引入Maven项目遇到的问题
- 项目图标不生效问题
- 关于 Spring boot 项目 偶然遇到 Failure to transfer org.springframework.boot:spring-boot-maven-plugin 问题的解决办法
- maven创建的工程css文件不生效问题
- maven 引入/导入 添加 spring 3 依赖
- sklearn 随机数据生成API (一)
- Linux下OpenSSL 源码安装的9个步骤
- Python之DataFrame数据处理
- 廖学峰老师的私家菜谱
- 《日本语能力测试阶梯导学听解专训N2》-初步的笔记
- maven项目引入spring boot依赖之后filter不生效的问题
- pdf2swf在线无法展示单页PDF
- 1056. 组合数的和(15)
- 目标检测中的尺度--An Analysis of Scale Invariance in Object Detection – SNIP
- leetcode 191. Number of 1 Bits(1的个数)(C++和Java)(无符号位)
- Influxdb基本概念及mac安装上手
- dbca 启动报错no protocol specified
- 使用dom4j时遇到了NoClassDefError
- crud.html