Spring annotation configuration does not find directories/classes in JARs - spring

I have the same problem as these guys:
Spring Annotation-based controllers not working if it is inside jar file
http://forum.springsource.org/showthread.php?t=64731
...but the difference is that I use Maven 2 as a build tool.
How do I achieve the same effect using Maven 2?
I saw this solution to creating a classpath entry in the manifest, but it generates a lot of absolute links to JARs which wouldn't make sense in my production environment:
Maven - how can I add an arbitrary classpath entry to a jar?

Maven 2 generates the directory entries, which is the answer to this question.

Related

How can I link to a liquibase changelog file inside a jar?

Currently, I have a multi-module maven spring project. I'm planning to separate one module and use it as a jar dependency. This module has all the liquibase change-log files that other modules in my project refer (through their own change-log files).
My question is, how should I refer the liquibase change-logs that are present inside the jar dependency? I've tried googling for hours but couldn't find a proper solution. How can this be achieved?
We created this example to explain how to deploy liquibase to multiple data sources using Springboot. You can check how the module and dependencies were created in the example database.

IntelliJ : how to verify log4j2.xml is on the classpath?

I'm working on a spring boot/maven project that I created with SpringIntializr. If I add all the necessary dependencies to my pom, and if I add my log4j2.xml to MyApp/src/main/resources,
and if after a build I see my log4j2.xml file in MyApp/target/classes, does that mean that the log4j config has been successfully added to the classpath?
I asked a more comprehensive question here, but thought this issue might merit a standalone question
Basically yes, what gets to the classes, later on, gets handled by the spring-boot maven plugin and should be available in the artifact that you build.
At this point it doesn't really matter whether it was originally in the src/main/resources folder or not.
Having said that, log4j2 is not used by spring boot by default (it uses logback), so you should set it up
For such a setup see this example

why are the github projects of spring-boot-starter projects empty?

On looking at the spring-boot-starter-web, spring-boot-starter-security projects on github, i find them to be empty with just a build.gradle file present there.
I hope this is as expected, but this leads me to understand where the actual source code can be found. And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
I hope this is as expected
This is as expected. Spring Boot's starter modules exist purely to being multiple dependencies together into a convenient "package". For example, if you want to write a Servlet-based web application using Spring MVC and Tomcat, a single dependency on spring-boot-starter-web provides all of the dependencies that you need. You can learn a bit more about the starters in the reference documentation.
Where the actual source code can be found
The majority of the code can be found in spring-boot-autoconfigure. For more production-focused features, you'll also find some code in spring-boot-actuator-autoconfigure. The code in these two modules is activated automatically when the dependencies that it requires are on the classpath. You can learn more about this conditional activation and auto-configuration in the reference documentation.
And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
Spring Boot is built with Gradle which, unlike Maven, completely separates the configuration needed by the build system to build the project and the information needed by a build system to consume the project. The build.gradle files provide all of the information that Gradle needs to build the project. As part of this, it generates Gradle module metadata files and Maven pom.xml files that contain all of the information needed to consume the project with Gradle and Maven respectively. These generated files are then published to Maven Central alongside the jar files, source code, etc.

Spring Boot Migration Issue on Packaging JAR and WAR using Maven

We are trying to migrate our existing Spring MVC applications to Spring Boot application. Our existing applications are using 3.2.9, so tons of XML configurations. All the beans are defined in the XML files. What we have done is first we have upgraded our existing applications to Spring 4.2.5 version since Spring Boot will work only with Spring 4 versions.
Our requirement is to have both FAT JARs and WAR files from the build. Most of our existing customers would prefer Application Server deployment, so we have to create WAR file for them. Also for our internal testing and new deployments, we are planning to use FAT JARs.
How can we achieve them in the Maven file, we are able to provide separately as below. Is there any maven plug-in to generate both in single build?
<packaging>jar</packaging>
or
<packaging>war</packaging>
We are publishing our artifacts into Nexus repository. So, we want to have the separate repository location for JAR files and WAR files. Can we do that using the single pom.xml file?
Also another question, we have all the XML configurations under WEB-INF folder. When we are moving to the Spring Boot application, it has to be under the resources folder. How can we handle them easily. When we build FAT jars, the resources are not looked under WEB-INF because it simply ignores the webapp project.
I am looking forward for some guidance to complete the migration. Infact, we have already done that changes and it is working fine, but we are confused on this WAR / JAR generations.
Update:
I have got another question in mind, if we are converting our existing applications to spring boot, do we still have to maintain WEB-INF folder in the web-app or can move everything to the resources folder?. While building the WAR file, whether spring boot takes care of moving the resources to WEB-INF? How spring boot would manage to create the WAR file if you are putting all the resources under the resources folder.
Building WAR and FAT JAR is very easy with Gradle.
With Maven, I would try multi module setup, where one sub-module will build fat JAR and second will build WAR file.
Application logic can be as third sub-module and thus being standalone JAR with Spring configuration and beans. This application logic JAR would be as dependency for fat JAR and WAR module.
WAR specific configuration can be placed in Maven WAR sub-module.
I didn't have such requirement before, so don't know what challenges may occur. For sure I wouldn't try to integrate maven-assembly-plugin or other packaging plugins with spring-boot-maven-plugin.
Concerning location of config files, just place them into src/main/resources or it's sub-folders according Spring Boot conventions. Spring Boot is opinionated framework and will be most friendly to you if you don't try to resist defaults.
Maven does not handle this gracefully, but its far from difficult to solve. You can do this with 3 pom files. One parent pom that contains the majority of the configuration, and one each for the packaging portion of the work. This would neatly separate the concerns of the two different assembly patterns too.
To clarify -- I'm not recommending a multi-module configuration here, just multiple poms with names like war-pom.xml and fat-jar-pom.xml, along with parent-pom.xml.

Maven: Managing Spring configurations

I have several set's of Spring configurations (XML files for bean initialization and properties files), for different kind of services/servers. I've also use maven to manage the dependencies and build (alternating with eclipse).
My intent was to have a flag I could pass to maven to build the project with a selected configuration profile.
Example:
mvn package production
will put the conf/production files in WEB-INF/classes
I've solved the problem by using the approach of Spring profiles as suggested by #gerardribas.
I've looked at the Jhipster implementation and follow that way. If somebody is following the same path, be aware that your need to upgrade your servlet version to 3.x.

Resources