Hallo,
ich habe folgendes Problem:
Drei Klassen entnehmen Werte aus der application.properties File. Es sind sehr viele Werte, mit zwei von drei Klassen klappt das sehr gut, aber bei der MentalPropertiesFormula2 Klasse will es nicht funktionieren. Durch verschiedene Versuche hat sich ergeben, dass das Problem ir-wie in der MentalPropertiesFormul2 Klasse liegt:
Die @ConfigurationProperties(...) Annotation funktioniert bei der anderen zwei Klassen, aber nicht mit der MentalProeprtiesFormul2. Wenn ich die Property Namen vollständig ausschreibe wie: "com.starter.tool.character.details.mental-proeprties-formula2.", dann funktioniert das, oder wenn ich ganz banal eigenen Wert in der @Value(...) einfüge, dann funktioniert es auch, aber es funktioniert nicht wenn ich zum Beispiel "mental-properties-formula2.selfcommunication" nehme, also sprich abkürze. Eigentlich müsste die Abkürzung funktionieren, da ich die @ConfigurationProperties("mental-properties-formula2") Annotation verwende, bei den anderen zwei Klassen klappt es. Hier ist der Ausschmitt aus der application.properties:
Zu dem ganzen erhalte ich folgende Fehlermeldung:
Also soweit ich das lokalisiert habe, liegt das Problem ausschließlich in der MentalPropertiesFormula2, da ich die Suche schon mal mit dem @ComponentScan(...) abgekürzt habe. Im Endeffekt dieselbe Fehlermeldung, also gibt es von außen keine andere Dependencies. Hat jemand die Vorstellung was da noch in die Frage kommt?
ich habe folgendes Problem:
Drei Klassen entnehmen Werte aus der application.properties File. Es sind sehr viele Werte, mit zwei von drei Klassen klappt das sehr gut, aber bei der MentalPropertiesFormula2 Klasse will es nicht funktionieren. Durch verschiedene Versuche hat sich ergeben, dass das Problem ir-wie in der MentalPropertiesFormul2 Klasse liegt:
Java:
package com.starter.tool.character.details;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties("mental-properties-formula2")
public class MentalPropertiesFormula2 implements Formula{
@Value("calm")
private String spiritualCondition;
@Value("${com.starter.tool.character.details.mental-properties-formula2.inner_personality}")
private String innerPersonality;
@Value("${mental-properties-formula2.selfcommunication}")
private String selftreatment;
...
// Setters + Getters
public String getSelftreatment() {
return selftreatment;
}
public void setSelftreatment(String selftreatment) {
this.selftreatment = selftreatment;
this.mentalFormular.add(selftreatment);
}
...
}
Code:
...
com.starter.tool.character.details.mental-properties-formula2.selfcommunication = selfdeception,
...
Zu dem ganzen erhalte ich folgende Fehlermeldung:
Code:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.3)
2023-10-29T14:18:35.637+01:00 INFO 3644 --- [ main] c.s.tool.PropertiesWorkApplication : Starting PropertiesWorkApplication using Java 20.0.1 with PID 3644 (C:\Users\iRahi\eclipse-workspace\PropertiesJSON\target\classes started by iRahi in C:\Users\iRahi\eclipse-workspace\PropertiesJSON)
2023-10-29T14:18:35.646+01:00 INFO 3644 --- [ main] c.s.tool.PropertiesWorkApplication : The following 4 profiles are active: "optimistic", "pessimistic", "active", "passiv"
2023-10-29T14:18:36.502+01:00 WARN 3644 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mentalPropertiesFormula2': Injection of autowired dependencies failed
2023-10-29T14:18:36.522+01:00 INFO 3644 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-10-29T14:18:36.562+01:00 ERROR 3644 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mentalPropertiesFormula2': Injection of autowired dependencies failed
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:489) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1416) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-3.1.3.jar:3.1.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[spring-boot-3.1.3.jar:3.1.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.1.3.jar:3.1.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.3.jar:3.1.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.3.jar:3.1.3]
at com.starter.tool.PropertiesWorkApplication.main(PropertiesWorkApplication.java:14) ~[classes/:na]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'mental-properties-formula2.selfcommunication' in value "${mental-properties-formula2.selfcommunication}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:191) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:920) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1358) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:713) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:696) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.0.11.jar:6.0.11]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:483) ~[spring-beans-6.0.11.jar:6.0.11]
... 16 common frames omitted