Custom configuration files are not resolved by Intellij Spring Framework - spring

Custom configuration files in seperate module are not resolved by Intellij and that prevents application to run via Spring run and makes all properties grayed out and not referenced.
But after I run it via Maven once, then Spring run works for some time. It was ok a month before but at some point it has broken.
Here is custom configuration folder:
PropertiesConfig(these files should not have been highligted because of not being resolved):
Properties file(properties are grayed out):

Related

Moved my spring boot application from mullti module to zero module and application.properties is not detected on IntelliJ IDEA

My application has a lot of modules, namely
entity
dto
rest-web
After removing all the module and combining the application like the default template in https://start.spring.io/, my application can start but it didn't recognize application.properties even though I have put the properties there.
Make sure that the parent pom.xml file does not have <packaging>pom<packaging>, otherwise the IDE wont recognize the spring application correctly

can spring auto reload changes like grails?

One of the main benefits of grails, which is based on Spring, is that you dont need to rebuild and re-run the entire application (which takes minutes) each time you change a line of code, it just recopiles that one file and auto-loads the changes.
Following this tutorial:
https://spring.io/guides/gs/spring-boot/
To run the app, you have to use the command line and do this outside of intellij:
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
If you change a line of code, e.g. in a controller, you have to kill the application, rebuild it and restart it, which takes a while.
I came across something called automatic restart in dev tools. Is this something to do with auto-reloading of changes, and if so, how is it used?
If a class is changed , I am sorry that Spring boot devtools will not just reload that changed classes but it will restart the whole application automatically . But this restart should be faster than the normal cold start based on what the docs said :
The restart technology provided by Spring Boot works by using two
classloaders. Classes that do not change (for example, those from
third-party jars) are loaded into a base classloader. Classes that you
are actively developing are loaded into a restart classloader. When
the application is restarted, the restart classloader is thrown away
and a new one is created. This approach means that application
restarts are typically much faster than “cold starts”, since the base
classloader is already available and populated.
If you need to just reload the changed classes , you may consider to use JRebel which is not free.
To use spring boot devtools , just includes its dependency and then start the application as usual using IDE.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
It will the monitor the classpath folders and then restart the application if there are any changes in these folders.
In case of Eclipse , what you need is to ensure Project ➡️ Build Automatically is selected. Once the source codes are changed , Eclipse will then just compiled that changed sources codes to the classes in the classpath folders automatically which trigger devtools to restart the application.
Based on the #Ken Chan answer but very briefly
For Eclipse - click in the menu "Project" -> select "Build Automatically"
In my case I was running some spring boot server - I had to stop the server, enable "Build Automatically" like on the picture, then start the server again and on every change - the code recompiled.

How to make Spring Boot skipping some configurations

I have a Spring-Boot project which works with DB-connections and a lot of other stuff.
Now I added another "main-class" to the project. The thing is: by starting this class, all configuration settings (which come from application.yml) are loaded. But thats not what I want.
I want the project to start without trying to bind to any datasource...
But how?
Why do you add several main classes? Try using different profiles instead. And you can start your application with the -Dspring.profiles.active=? property.
Example:
Just add a application-test.properties and run your application with -Dspring-profiles.active=test and the properties in the test property file will be loaded. And potentially overwrite properties with the same key in application.properties.

Intellij IDEA Inspection Ignores Config Folder

I have a Gradle based Spring Boot application which requires an external properties file. Fortunately, Spring Boot automatically looks for an application.properties file in a /config folder by default, so I put that in the module root and it works fine. However, it seems that IDEA's inspection is marking everything in this file as "Unused Property". If I move the file to /src/main/resources the inspections work properly.
So, what is the best practice when working with these external properties files? Is there something I can set in the build.gradle to get IDEA to recognize the properties or some setting in IDEA? I've tried playing around with the Spring Facets in the project settings, but can't seem to figure it out.
Thanks!

Eclipse Java EE project and Spring : classnotfoundexception

I am trying to build an project in Eclipse (actually I'm using RAD, so basically eclipse, and when I say 'Java EE Project' I mean an 'Enterprise Application Project').
My Enterprise Application Project (the 'EAR' project) has two module projects :
- service
- web
The service project has some stuff in it, all wired up using Spring.
The web project has its own stuff in it, all wired up using Spring. The UI stuff in the web project needs to use the stuff in the service project.
Both projects are included in the EAR project as modules.
The web project lists the 'service' project as a dependent project in the build path, it's checked off for export, and also has it listed as a EE Module Dependency.
I'm having a really hard time to get this working though:
The spring context in the web project is of course what gets loaded when the application is deployed, and it imports the spring config I need from the service project. This seems to be working fine.
When spring tries to instantiate a bean it throws a ClassNotFoundException. On the very first bean.
I tried simply copying the spring config from my service context and pasting it into my web context, but I got the same ClassNotFoundException.
I have tried instantiating an object of that type (the class that spring says cannot be found) in the java controller class in the web project, and it is successful, both at compile time (no compile errors) and at runtime (no exceptions).
So the classes from my service project are not available on the classpath when spring tries to use them.
Any ideas what's going on here and/or what I might be able to do about it?
There is a class loader policy that you should use ParentClass First . That will be managed either through Application.xml or through web.xml . You need to check your xml's then try.
It's a class loader issue.
Since you're using Spring, I'll assume that you don't have EJBs. If that's the case, why do you need an EAR? Deploy the whole thing as a web project, in a single WAR.
Put all your .class and Spring configuration .xml files in WEB-INF/classes. Load the configuration using org.springframework.web.context.ContextLoaderListener.
I seem to have fixed this - I'm not sure exactly what the problem was but there must have been a small typo in my spring config. I decided to just start fresh with a new spring config and when I started building the new one back up things were working fine. There must have been a problem with the old one.
Thanks for the suggestions though.
Unfortunately we're not always able to change project structure. We're working on structures other people have put in place.
I looked into the ParentClassFirst vs ParentClassLast setting - it seems on websphere the ParentClassFirst setting is the default if you don't specify anything, so I'm leaving it without specification to get that functionality.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/crun_classload.html

Resources