Spring Tools Suite stopped to exclude test classpath from RUN AS - spring-boot

I am using STS to develop a Spring Boot based application. I have multiple maven projects and a patent one to include them all.
I used to run/debug the application by calling RUN AS/DEBUG AS Spring Boot Application to the project that contains the Spring Boot main entry class.
Something changed and the STS loads to the application running classpath the test classes as well. That causes conflicts to spring bean initialization.
Is there any configuration in the workspace that causes that behaviour?
I also created a new workspace, but No luck :-(

I know it's a 6 month old question, but for those still having the issue:
You should open your "Run Configurations"
under "Classpath" tab
verify that "exclude test classes" is checked
It seems that new STS' Spring Boot App "run configurations" are created without this option (while it's checked by default for standard Eclipse's Java main class)

Related

Debug Spring Boot 3 in IntelliJ Community

Since the migration to Spring Boot 3 my application doesn't hold at breakpoints any more, when I run the Maven Spring Boot goal mvn spring-boot:run.
This is because Spring forks the thread or the process and the debugger is not attached to this.
In former Spring-Boot versions you could disable forking by passing -Dspring-boot.run.fork=false (see How to debug spring-boot application with IntelliJ IDEA community Edition?).
Unfortunatly this option was removed as you can read in the Spring Boot 3.0 Migration Guide:
The fork attribute of spring-boot:run and spring-boot:start that was deprecated in Spring Boot 2.7 has been removed.
Is there any possibility to make breakpoints work again?
Ideas so far
Of course IntelliJ Ultimate has better Spring Boot integration. I'm trying to make it work with the Community Edition.
I also tried not to run the Maven goal but to make an Application run configuration. This failed so far, because of java.lang.ClassNotFoundException, it doesn't find the Main class. Not sure if I should investigate that option further.
Last idea was to start the Maven goal with debug options such that an external debugger can attach. That didn't work either and even if it would, I could only attach the debuger after startup with would make debugging the creation of spring context impossible.

Deploy Spring Boot project to WebSphere 8.5.5

I'm trying to deploy my spring boot project (made by spring initializr) with maven (but same issue with gradle) on WebSphere Application Server 8.5.5 but it seems impossible to me.
Every-time I try to add to server from "Add and Remove" it says "There are no resources that can be added or removed from the server".
So I tried changing Dynamic Web Module on Project properties --> project facets but nothing changed.
Is it possible to deploy on WAS 8.5.5?
I found a similar reported issue here: Cannot 'Add and Remove' Maven Project with Websphere 7 on RAD 8.5.
I completely removed my project from RAD. I then extracted zip file from Spring Initializr to create a Maven project. I used "mvnw eclipse:eclipse" command and it successfully created build. I imported that as a general project to RAD.
I then clicked on project. Clicked on properties. Clicked on project facets. None were available, but it prompted me to create them and I did. From there, I selected Dynamic Web Module facet (and also JAX-RS, but I'm not sure if you'll care about that one). I clicked apply and close.
After this, I was able to add and remove resource to Websphere server. I don't know if this is preferred steps or not. I am learning, just as you are. But, it appeared to work.
I specified Java 8 Jar in Spring Initializr for packaging. Maven version is 3.8.4. Spring Boot 2.6.5 (it was pre-selected for me). I am using RAD 9.7 and Websphere server that is stood up in IDE is version 8.5.5.
To deploy spring boot to WebSphere 9 you would want to choose War packaging and Java 8. The zip file from the spring initializr includes a Help.md file with links to helpful documentation. After you extract the zip file, use File -> Import existing maven project into a new workspace.

can you help me fix my STS? as it is not working

I am new to STS and trying to run my first project in it. But it is not showing me run on server option. I have tried "clean install" but still, it is not working. When I checked targeted runtimes it is not showing any server in it. Kindly help me to resolve this issue.
My recommendations for getting started with the Spring Tools 4 for Eclipse are:
start the IDE with an empty workspace
create a new Spring Boot project using the wizard "Import Spring Getting Started Content" to import some getting started guides, for example the Rest Service example
if you decide to create an empty new Spring project, use the wizard "Spring Starter Project" - it is the direct integration for https://start.spring.io - and go from there
All those options get you started with a Spring Boot project which doesn't need a separate server to run on. Spring Boot comes with am embedded server component, so you can just start the Spring Boot application as a regular Java app. No need to install a local server or use the "Run on Server" option in the IDE.

Converting existing project to Spring boot project in InelliJ

I have an existing project. I need to make it a Spring boot based project and I am using IntelliJ CE.
What would be correct procedure for doing it?
Edit:
Project has no initial structure. It is a totally empty project. So no existing modules etc.
Spring Boot is an Ultimate feature, so first you would need to try/buy the IntelliJ IDEA Ultimate.
From there, you can add Spring support to existing project modules or use the Spring Initializr wizard to select the necessary configuration when creating a new project or module.
In your maven pom.xml or build.gradle file, I would add the spring boot starter dependency:
spring-boot-starter (the group id is org.springframework.boot)
If the application is a web application, I would also add the web starter spring-boot-starter-web also with the same group id (org.springframework.boot)
For convenient features, applying the spring boot plugin would help in creating a runnable jar with all required dependencies bundled called a fat jar.
A great tool I use is the spring boot project generator. It allows you to configure the modules you want and create a project template.
Spring Boot requires IntelliJ IDEA Ultimate. If you want to use IntelliJ CE, please create a project using Spring Initilizer then import the same to your IntelliJ CE (File -> Open -> Choose the project root folder). After you import the project, wait for some time so that IntelliJ can download the dependency and build your project. You can check from (Build -> Build your project). Then find the main class of spring boot and run it using the green play button

Configuring Spring security with spring boot on already created project, IntelliJ

I have previous experience in Spring MVC but I am new to Spring Boot.
I am Using IntelliJ for the first time.
What I noticed is that when you create a Spring boot project with security dependencies added during the time of creation, Then the IDE creates the project already configured With Basic Authentication whereas if I add dependencies to pom.xml after creation, then the application won't get configured with basic authentication automatically.
Can anyone explain this behavior of IntelliJ and can anyone help me with steps for configuring the pre-created project with Basic Authentication?
IntelliJ is using
https://start.spring.io/
to initialise your project. After the project is initialised, the IDE doesn't modify your code in any way. That is the normal behaviour and it is not Spring Boot related.
NOTE: The dependency that you add in your pom.xml is just pulling down that dependency, but if you need to use it you do the code yourself. (More information about Maven: https://en.wikipedia.org/wiki/Apache_Maven)

Resources