what is reason the spring boot application doesn't read application.properties file? - maven

i have a maven project then i'm manually added a 'src/main/resources' directory and application.properties but it can't read the application.properties file;
How can i convert my maven project to spring boot project ?

You need to say your IDE that src/main/resources is a source folder.
Try a maven plugin (e.g. for Eclipse http://maven.apache.org/plugins-archives/maven-eclipse-plugin-2.8/eclipse-mojo.html),
do it manually
start your application using the maven spring-boot plugin
mvn spring-boot:run
http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html

Related

mvn:spring-boot run is not working for Spring Boot Ear package

Have created Spring Boot EAR project
parent
-- ear
-- war
Ear
--war
Go to war spring boot project inside parent project and execute mvn:springboot run throws following error. If I create individual spring boot war application with no ear package, then mvn:springboot run command is working.
org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'spring' in the current project and in the plugin groups [org.apache.maven.plugins, o
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve (DefaultPluginPrefixResolver.java:95)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix (MojoDescriptorCreator.java:266)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor (MojoDescriptorCreator.java:220)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments (DefaultLifecycleTaskSegmentCalculator.java:104)

Spring Boot Gradle bootRun task default classpath and current working directory

I am going to test external config for application. What is default classpath and default working directory for Spring Boot Gradle bootRun task?
I didn't get in from:
http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html
UPDATE test with System.getProperty("user.dir") show that current directory is where Gradle is started.
Working directory is actually the module with Spring Boot project, which does not necessarily have to be the rootProject.
Classpath for bootRun is:
working directory (or Gradle project directory with Spring Boot)
main classes
runtime classpath
At least this is what seems to be the default when I debug the build (now easily possible with IntelliJ IDEA 2018.2).

Use of spring-boot-maven-plugin

While creating a spring boot project I define property in pom.xml as <packaging>war</packaging> with which I can create a war and thereafter deploy the war into server maybe tomcat or WAS.
But I came across a plugin named spring-boot-maven-plugin whose documentation states that it's use is to package executable jar or war archives and run an application in-place.
My query is why do we need this at all ?
If my packaging can tell me what to create and then can deploy it to run, what is the used of this plugin.
I am trying to understand a new project so wanted to be sure that every line makes sense
The maven plugin will create an "executable" archive. In the case of the war packaging, you would be able to execute your app with java -jar my-app.war. If you intend to deploy your Spring Boot application in an existing Servlet container, then this plugin is, indeed, not necessary.
The maven plugin does more things like running your app from the shell or creating build information.
Check the documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven, letting you package executable jar or war archives and run an application “in-place”.
Refer this - https://www.javaguides.net/2019/02/use-of-spring-boot-maven-plugin-with.html

Spring Boot Initializr: Maven project or Maven POM?

I want to set up a Spring Boot project using the Spring Initializr (https://start.spring.io) but I was wondering about the difference in the project type you can choose between: Maven Project or Maven POM?
What is exactly the difference between these two types?
Maven POM creates only the pom.xml file.
Maven Project creates the pom.xml file and a sample project including src folder:
> src:
> main:
> java:
> com.example:
Application.java
> resources:
application.properties
> test:
> java:
> com.example:
ApplicationTest.java
> pom.xml
Maven Project is the type which we use to create a common Spring Boot application. It seems Maven POM is for downloading build scripts only.
Basic difference that you even experience it by selecting the maven project option and say download, you get a maven which includes sample spring boot application
Other case you have existing project and want to add spring boot then you can simply get the configuration to include spring boot artifacts

Jar files for spring-hibernate integration

I'm working on Spring Hibernate Integration program as Ant with MySQL but I'm stuck with which jar files to add and at which location
I'm using org.springworks.orm.hibernate.*. Which specific jar file needs to be added?
You can download the jar from MVNRepository.
But as suggest by M. Deinum, you should try upgrading to Maven or Gradle.

Resources