I am running a Spring boot Java app in Netbeans 9.0 which has two profiles (test, production). I need to run the project in 'test' profile instead of the 'default'
I have tried the following setups
Setup 1
Project (Right click) > Properties > Run > Arguments
-Dspring.profiles.active=test
Setup 2
Project (Right click) > Properties > Actions > Run Projects > Activate Profiles
test
The configuration doesn't work correctly and I am getting the following message
"No active profile set, falling back to default profiles: default"
Could you please help me to set up this configuration
After poking around a bit, I found that from Netbeans 8.1 and up you can do the following to set a Spring profile:
Right click your application -> Run Maven -> Goals -> In the "Properties" section set:
-Dspring.profiles.active={your profile name here}
This worked for me.
Have you tried configuring profiles in the application.properties or application.yml in your spring boot app?
Please read this documentation
Spring Boot Profiles
I suppose you have installed this plugin to NetBeans.
Then right click on the Project -> Properties:
Important: The argument starts with "--" (not "-D") since it's a spring boot command.
Related
I want to set a system property when running a spring boot application in IntelliJ, and then get it in my program. I am using IntelliJ Idea CE.
Initially I tried in a normal Java project (not spring or maven). I just set the value in "VM Options" in run configurations (Ex: -DpropertyName=propertyValue). And then I ran the main function, I was able to access it by System.getProperty("propertyName").
Now I want to do the same with my spring boot project. Its packaging is war. As I am using Community Edition, I run the project by running the maven command spring-boot:run. How do I pass a system property here?
I have tried adding the property in "VM Options" in the run configuration.
I have tried below commands -
spring-boot:run -DpropertyName=propertyValue
spring-boot:run --propertyName=propertyValue
spring-boot:run -Drun.jvmArguments="-DpropertyName=propertyValue"
But in all approaches, when I am getting the property value in my method, it gives null.
Any suggestions are welcome.
EDIT Adding code snipped as requested
public static boolean isSomething() {
return !StringUtils.equals(System.getProperty("propertyName"), Constants.CONSTANT_VALUE);
}
How to override spring boot properties at runtime?
Below command works fine in terminal
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8081
but it's not working in Eclipse
-Dspring-boot.run.arguments=--server.port=8081
You have two options.
You can configure server.port=8081 in application.properties file in spring boot application.
Configure only -Dserver.port=8081 in VM arguments in eclipse as displayed in the image.
Use -Dserver.port=8081 as vm argument from run configuration of eclipse. It will work
my application.yml locate
my application.yml
spring boot run server port
Intellij spring boot run configuration
Hi.
My project is Intellij spring boot 1.5.7 Gradle Project
When Intellij spring boot run cannot load application.yml automatically.
but gradle bootRun is very well run&load.
Please suggestion me.
You should specify profile configuration. From your application.yml, you have multiple configuration separated by "---", this is used for multiple profile configuration for different spring profile. Try removing "---" and specify profile as following :
Multiple configuration is used when you have different configuration for different profile, as following:
What's the problem?
Is it possible to debug a Gradle web app running via Jetty plugin (using jettyRun or jettyRunWar) by using a IntelliJ IDEA Run/Debug Configuration?
I know that it is possible (I've done it before) to do it with Maven/Tomcat7 plugin and creating a simple Maven Run/Debug Configuration with the clean package tomcat7:run goals.
I've tried to create a Gradle Run/Debug Configuration with the clean jettyRunWar tasks. If I Run the configuration, everything works well. But the Debug option is not working as expected: the application actually runs, but debugger won't connect.
However, I did manage to debug the project by running on debug mode externally, like this:
$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
$ ./gradlew clean jettyRunWar
And then creating a Remote Run/Degug Configuration with all the default configurations except the port, which was set to 9999.
But that's not the solution I was looking for. I want to be able to debug the project by only clicking a button. Am I missing something?
Not in the mood to read everything? Here's an example
I've created a simple IDEA/Gradle/Jetty web app using Jersey available on Github here. The problem can be reproduced by:
Cloning the repository
Importing it on IDEA
Creating a Gradle Run/Debug Configuration for the root project with the clean jettyRunWar tasks
Debug using the configuration
The debugger won't connect and breakpoints won't work.
I am using:
IntelliJ IDEA Community Edition 2016.1.3 (OS X)
Gradle 2.7 (a wrapper is available on the Git repository, so it doesn't matter)
while running maven from eclipse you have option to execute these launch configurations by default .. here is the image of that :
Now I can add my own launch configurations and execute them. Like this :
Now instead of running run configurations every time, is it possible that I put my own launch configuration called "Clean install skip tests with assembly" instead of default run configuration #1(Maven assembly:assembly) or can I add #10 configuration to be my created configuration. Thank you
Now instead of running run configurations every time, is it possible that I put my own launch configuration called "Clean install skip tests with assembly" instead of default run configuration #1(Maven assembly:assembly) or can I add #10 configuration to be my created configuration.
I don't think so. But once you've run your Maven Build Run Configuration, it should be listed under the "Run As..." green arrow:
alt text http://img8.imageshack.us/img8/8510/screenshotrun.png
And you can add it as favorite if you want.
When you select Run As > 2 Maven Build (the one with the shortcut. It may not always be 2) you can choose which run configuration to use from a simpler dialog - including your custom.
For skipping tests dont add -D in the goals field. Use the "Skip Tests" checkbox that is below the Profiles input box adn it should work :)