在 idea中拷贝 application.properties 的疑惑 ?

来源:8-2 讲师头像的保存与显示

慕神4535282

2021-02-24

老师,新年好。
我在做本节时,在 idea中,把 A 工程 file 模块下的 application.properties 拷贝 到 B 工程中,运行B 工程的 file 模块会启动失败。



17.819 INFO  c.q.f.config.FileApplication  :651  No active profile set, falling back to default profiles: default
19.273 INFO  o.s.c.c.scope.GenericScope    :295  BeanFactory id=378970f0-b3a9-33c6-99c9-97b1c3e99b12
19.491 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker:330  Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
19.601 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker:330  Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
20.054 INFO  o.s.b.w.e.t.TomcatWebServer   :92   Tomcat initialized with port(s): 8080 (http)
20.069 INFO  o.a.c.http11.Http11NioProtocol:173  Initializing ProtocolHandler ["http-nio-8080"]
20.069 INFO  o.a.c.core.StandardService    :173  Starting service [Tomcat]
20.069 INFO  o.a.c.core.StandardEngine     :173  Starting Servlet engine: [Apache Tomcat/9.0.29]
20.257 INFO  o.a.c.c.C.[.[localhost].[/]   :173  Initializing Spring embedded WebApplicationContext
20.257 INFO  o.s.web.context.ContextLoader :284  Root WebApplicationContext: initialization completed in 2406 ms
20.320 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:558  Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'file.domain' in value "${file.domain}"
20.320 INFO  o.a.c.core.StandardService    :173  Stopping service [Tomcat]
20.320 WARN  o.a.c.l.WebappClassLoaderBase :173  The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
20.335 INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener:136  

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
20.335 ERROR o.s.boot.SpringApplication    :826  Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'file.domain' in value "${file.domain}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at com.ql.file.config.FileApplication.main(FileApplication.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'file.domain' in value "${file.domain}"
	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)
	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
	at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236)
	at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:908)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1228)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	... 20 common frames omitted

Process finished with exit code 0

我找了相关的资料,讲的都是 .yml 文件的, 而且,问题与我的情况不符。
后来我研究了大半天,发现,如果对 B 工程的 application.properties 手动敲代码追加进去

file.path=D:/file/ql/course/
file.domain=http://127.0.0.1:9000/file/

是可以正常启动的,

但是,如果从 idea 中A工程file模块 application.properties 拷贝到 B 工程的相应目录下,就会出现上述的错误。(注: A 工程的 application.properties 同样也有

file.path=D:/file/ql/course/
file.domain=http://127.0.0.1:9000/file/

)

我仔细检查并重复了多次,排除了任何操作上的失误,并且,我把 可以正常启动 file 模块时的 application.properties 和不能正常启动 file 模块时的 application.properties做了文本比较和 16进制比较,两者完全一样,大小一样,16进制的每一个字节都一样,
请问老师,这是怎么一回事啊?为什么会出现这种情况?
谢谢老师指导!!!

写回答

1回答

甲蛙

2021-02-25

从报错看出来是找不到配置

//img.mukewang.com/szimg/6037023f094ca2f608970053.jpg

从你的描述看不出问题,你是从A的配置文件替换掉B的本身的配置文件吗?有没有试过只拷贝这两行,而不是替换整个文件

A,B是两个项目?还是一个项目下的两个模块?互相之间有没有依赖,如果有依赖就可能出现配置文件覆盖的问题

0
3
慕神4535282
回复
甲蛙
看了,在idea 的右下角,两个文件(可以成功启动的和不能成功启动的)的application.properties都是显示 CRLF UTF-8,
2021-02-26
共3条回复

Spring Cloud+ Vue前后端分离开发企业级在线视频系统

全网稀缺课程 市场热门项目+主流框架 一课掌握前后端技术

1743 学习 · 1697 问题

查看课程