Spring 4 submodule annotaions - spring

I am using Spring 4.x for my latest project, no xml, only annotations. It was working fine till I decided to move part of my project into a submodule. I see the submodule jar in the lib folder of the project jar (used spring boot jar maven plugin to package).
The problem now is that Spring does not recognize the components in the submodule jar. The package names are the same for both the jars.
sample code
#EnableAutoConfiguration(exclude={JmsTemplateAutoConfiguration.class})
#ComponentScan("com.abc")
Structure
project.jar+
|-lib+
|-submodule.jar
Spring loads all the beans / components in the project for that package, but nothing from the embedded jar file.
Stacktrace excerpt:
No qualifying bean of type [com.abc.xxxx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency....
What am I doing wrong here?

It's not a great idea to split packages across multiple jar files. I imagine it will work if you name the packages uniquely. Please raise an issue in github if you think it might be fixable in the class loader.

Related

Does quarkus-maven-plugin support multi-module projects?

I'm trying to convert a multi-module Maven project from vanilla Java EE 8 to Quarkus, and it seems that ArcAnnotationProcessor throws exceptions about unsatisfied dependencies for all injection points referencing dependencies located in a different module.
Is there any workaround, short of merging the modules?
Answering my own question:
According to the Quarkus CDI guide,
The bean archive is synthesized from:
the application,
application dependencies that contain a beans.xml descriptor or a generated Jandex index (META-INF/jandex.idx),
and Quarkus integration code.
After adding a beans.xml to each of my reactor modules, ArC no longer complains about missing dependencies.

Dependency conflict in pentaho data integration when an external jar is called from UDJC step

I have a spring project which is deployed in libext folder in Pentaho Data Integration and called from "User Defined Java Class" step. I get a java.lang.NoSuchMethodError: org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate The project has a dependency on org.springframework.spring-jdbc (version 4.1.7) which has batchUpdate method in NamedParameterJdbcTemplate. However, the Pentaho lib folder has spring-2.5.6 jar which has org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate which probably doesn't have batchUpdate method. How can this dependency conflict be resolved..I have Pentaho CE 5.3.Thanks in advance.
In addition to placing the jar file into /libext, you will also need to modify /launcher/launcher.properties to look for user defined libraries in libext. It will take effect on the next restart of Spoon.
libraries=../test:../lib:../libswt:../libext
classpath=../:../ui:../ui/images:../lib:../libext
After a bit of R&D, I figured it was the problem with the version of spring jars used. Pentaho DI 5.3 has org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate class in spring2.5.6 jar which doesn't have batchUpdate method. My project was built on spring 4 which has batchUpdate method in spring-jdbc jar. This was causing the dependency discrepancy and hence the NoSuchMethodError. I fixed it by using a later version of Pentaho DI (version 6.1) which internally uses Spring 3 and has no such conflicting jars.

Spring with maven-shade-plugin

I am trying to use to versions of spring in the same application: the first one is a webapp with spring 2.6 and the second it a jar client, with spring 4.0.2. The client communicates with another application and will be a dependency for the webapp. The problem is that the classloader will just load one time the common classes from spring and it will certainly fail.
I tried to use ElasticSearch aproach of using shaded dependencies(maven shade plugin) and relocate spring from the client to a different package (from org.springframework to my.springframework) and the uber jar seems to be constructed fine.
The issue is that Spring is based on spring.schemas and spring.handlers for validating xml config files and loads this files from classpath (META-INF folder and this paths are hardcoded in Spring code - e.q. PluggableSchemaResolver). I modified this files to point from org.srpingframework to my.springframework.
At runtime it seems that the classloader reads these files from the webapp, which has this files but with the real spring path and the exception is something like
org.realsearch.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [my.springframework.beans.factory.xml.NamespaceHandler] interface.
To me it seems that is impossible to achieve what I am trying (use tho spring versions in the same application with one of them relocated). Any ideas here? Am I wright?:d

What is a general way to use a Spring project inside another?

I have a Spring project which is a regular jar file. It uses JPA and Spring Data.
I'd like to use it in another Spring project, which is a war running in Tomcat. It also uses JPA and Spring Data.
I have installed the jar into the local maven repository, and have declared it as a dependency in the parent project.
What do I need to do to make them work together correctly?
Are there naming conventions for the various context, properties, and persistence files?
Do I need to import the library configuration files in the "parent" configuration files?
I am getting the following error when trying to run the parent:
IllegalArgumentException: Not an managed type: class [some domain class in the parent project]
Use Maven Modules. Reference here:
http://books.sonatype.com/mvnex-book/reference/multimodule.html

Spring autowiring classes between 2 distinct project

I'm trying to autowire classes between 2 projects with spring (using eclipse IDE). So I added to the first project the second project to the build path. The imports are resolved correctly but when I launch the app the log tells me that he can't find the class which I'm trying to wire to.
The classpath have solved the problem.

Resources