Spring profile unable to parse correct file - spring

This is the code that I'm using to reading the application.properties file in a gradle project.
#PropertySource("${spring.profiles.active}/application.properties")
My file is located inside resources/local/application.properties
This is how I'm trying to run the application in IntelliJ
This is the error that I end up getting.
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.core.Application]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.profiles.active' in value "${spring.profiles.active}/application.properties"
Can someone help me fix this and read the correct config.

You're trying to get spring.profiles.active but in Intellij you're setting spring.active.profiles

Related

gradle7.4.2 can not implementation local jar

gradle7.4.2 can not implementation local jar
the error is npe.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':client:rest'.
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116)
Caused by: java.lang.NullPointerException
I need to use local jar into project, used gradle 5.4.2 is success, but use 7.4.2, always error...
I use many method to test, but can not access...
enter image description here
how to handle the exception?
thanks~~~

How run spring boot jar with class path resource

I have a spring boot application. It works perfectly if I run it from Eclipse. But if I run the same from command prompt, I am getting the following error
ERROR
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.core.ProducerFactory]: Factory method 'kafkaProducerFactory' threw exception; nested exception is java.lang.IllegalStateException: Resource 'class path resource [kafka/somejksfile.jks]' must be on a file system\r\n\tat
I extracted the .jar file and I was able to see the Kafka related .jks file inside
projectName\BOOT-INF\classes
For some reason it is not picking all the files which are inside src/main/resources. How to refer that location when running the .jar from command prompt. I tried the following with no luck
java -jar -Dspring.profiles.active=dev -Dspring.config.location=file:\\C:\my-files\poc\projectName\src\main\resources\ api-account-info.jar
Note: I cannot make any code changes
I resolved the issue by the following.
Downloaded Spring Boot CLI and extracted it. (https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.2/spring-boot-cli-2.6.2-bin.zip)
Set environment variable
Variable: SPRING_HOME
Value: C:\my-files\Installations\spring-boot-cli-2.6.2-bin\spring-2.6.2
Variable: Path
Value: %SPRING_HOME%\bin
From command prompt run the following commands
SET SPRING_PROFILES_ACTIVE=dev
mvn spring-boot:run
This will build and start the application.

OutOfMemoryError by using gradle

I am new to Gradle. I am using 5.4.1 version. When I am trying build the application I am facing below issue -
java.lang.IllegalStateException
Caused by: org.springframework.context.ApplicationContextException
Caused by: java.lang.OutOfMemoryError
I have added gradle.properties file in my project root directory where build.gradle is present with below property but still facing issue.
org.gradle.jvmargs=-Xmx512m
I am not sure where to add gradle.properties file. I have also refere this https://gradle.org/docs/current/userguide/build_environment.html document but not sure why gradle.properties files not read by the application.
I am trying to connect remote kafka server from my application and error is
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is java.lang.OutOfMemoryError: Java heap space
The default max heap size of jvm is 512m according to the Gradle doc. Can you try increasing it and setting it like :
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
Or you can try setting it in global in environment variables GRADLE_OPTS
From doc:
The org.gradle.jvmargs Gradle property controls the VM running the
build. It defaults to -Xmx512m "-XX:MaxMetaspaceSize=256m"

Spring-boot app working in IDEA but crash when running jar - “Unable to resolve persistence unit"

Updated:
It's been days that I tried to accomodate some times in between then came back to this code-base, but still faced up the same issue.
I am frustrated that have a Spring Boot 1.5.12 application that worked in IDEA but failed when running executable jar in Unix box, and the stack trace follows this format that I needed to trim the stack trace for relevancy:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxEntityManager' defined in class path resource [com.abc.persistence.ConfigClass]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
................. [Skipped the stack strace]
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:602)
... 48 common frames omitted
As per suggestion by Getting "Unable to resolve persistence unit" error when building jar without IDE, I tried this workaround of 2 changes but it doesn't work at all.
1)#EnableAutoConfiguration(exclude = HibernateJpaAutoConfiguration.class) to my application class
2)spring.data.jpa.repositories.enabled=false to my application.yml file in src/main/resource/ directory
Even with those two changes being added, it still shows the same error.
I hope someone can help me figure out this frustrating inconsistency occured between the run time behavior in IDEA and executable jar in console.
Edit:
I used Gradle build script with this build task applications to build the app jar executable whose jar pull everything of src files in package names and resource property configuration yaml files besides gradle build:
applications {
...
}
So I've been tried to crack the root cause that runs my life nuts, which is based on this possible mystery:
Can someone know about jar (JVM) process of how it processes to create jar artifacts that in the end when I face the extremely weird anomaly where Intellj has always been able to set the persistence unit URL to default, whereas running on jar doesn't accomodate this auto-configuration already coded in the app and property codes?

jboss-as-greeter-spring won't build

I am trying to get the JBoss Developer Network greeter spring project working but it is erroring out with the following error:
Build path is incomplete. Cannot find class file for javax/servlet/ServletContext
Anyone have any ideas on how to get this working.

Resources