Updating from Spring 3.0.5 to Spring 3.1.2 does not include aspectjrt as a dependency - spring

I am updating from Spring 3.0.5 to Spring 3.1.2 and while updating spring security core is also updated to 3.1.2 which in turn has dependency on aspectjrt (mentioned in its pom) but after updating to 3.1.2 if i generate dependency tree using
dependency:tree
it does not list aspectjrt in the tree but if i generate the same tree using version 3.0.5 aspectjrt is listed in the dependency tree.
Also, as previously mentioned I have already verified that aspectjrt dependency exists in both poms (version 3.0.5 & 3.1.2).
Since aspectjrt in not listed as a dependency my code is not compiled as it requires classes from aspectjrt.
If i explicitly inlude aspectjrt dependency in my pom my code compiles successfully.
Does anybody have any idea why this issue is occuring after updating to 3.1.2? Why aspectjrt is not inluded as a dependency after updating to 3.1.2
Is there any workaround for this or i will have to work by including aspectjrt as explict dependency in my pom.

AspectJ is declared as optional dependency in spring POM. Which means that AspectJ is required to build Spring JAR but is not required to build your project when you include Spring as dependency. If you need AspectJ functionality, include it in your POM.

I have solved the issue. This is the expected behavior as spring security core 3.0.5 aspectjrt is not optional but in spring securoty core 3.1.2 they have marked aspectjrt as optional.
So,if you are using some piece of aspectjrt in your code you will have to include aspectjrt dependency in your pom.
Hope that helps.

Related

Spring Boot autoconfigure and its dependencies

I checked the source code of module spring-boot-autoconfigure
It has configurations classes for plenty of technologies : data, redis, cassandra, JPA, LDAP etc...
How can this module can compile properly without including all theses technologies dependencies jar in its POM ?
If I take the example of HibernateJpaAutoConfiguration class :
It uses beans/classes from other Spring modules like spring-orm :
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
However spring-boot-autoconfigure has no dependency to spring-orm in its POM. So how is compilation possible ?
This is possible because they apply Maven's concept of optional dependencies:
Optional dependencies are used when it's not possible (for whatever reason) to split a project into sub-modules. The idea is that some of the dependencies are only used for certain features in the project and will not be needed if that feature isn't used. (...) However, since the project cannot be split up (again, for whatever reason), these dependencies are declared optional. If a user wants to use functionality related to an optional dependency, they have to redeclare that optional dependency in their own project.
In Maven, it would usually look like this:
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
In this example, the project is compiled with Project-A. However, Project-A is not shared as transitive dependency.
The developers of Spring Boot use Gradle instead of Maven. They wrote their own Gradle plugin to replicate this behavior. The result looks something like this:
dependencies {
...
optional("org.springframework:spring-orm")
(see spring-boot-autoconfigure/build.gradle)

spring boot project as dependency inside another spring-boot project

I have a spring boot project(project-lib) which I am including as maven dependency in another spring boot project(my-project).
now the project-lib uses logback and i want to exclude the logback dependency in my-project.
Also currently project-lib is defined as dependency with classifier jar-with-dependencies
Is it possible to define project-lib as normal dependency instead of jar-with-dependencies.
I tried to define it as normal dependency assuming it will download all the required dependencies as project-lib/pom.xml has already defined the required dependencies to run project-lib but it did not work that way.
part of pom.xml of my-project
<dependency>
<groupId>com.xyz/groupId>
<artifactId>project-lib</artifactId>
<version>0.0.4-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>

Which spring-test jar version to use with Spring Integration

We are using Spring Integration version 2.2.0.RC2.
When running tests, the following exception is thrown:
java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
I understand this is because of a clash of Spring jars, likely due to the wrong version in the following maven dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
When using Spring Integration version 2.2.0.RC2, which version of spring-tests should be used? Furthermore, what is the best way to resolve these kind of Maven clashes in future - is there a listing of compatible versions of Spring jars?
Thanks
If you a do a mvn dependency:tree are there any org.springframework:spring-core libraries in there that are not at the expected levels?
Run that and make sure your spring version numbers are ALL consistent. Use dependencyManagement stanzas to ensure they're consistent.
This issue had the same symptoms.
We run a nightly build of SI against Spring 3.2.x; 3.1.3 is simply the minimum supported dep. To use a newer version of Spring, you can <exclude/> the transitive dependencies in your POM.

Maven including older version of spring

I have a maven project in eclipse with m2e plugin. Dependency hierarchy is showing it is omitting spring 3.2.3 in place of 3.0.0.RELEASE as shown below. How to do it otherwise? Should it not omit the older version and keep the latest?
Maven works on the principle of nearest wins strategy while resolving the dependency conflicts , that means whichever version it finds nearer in the tree , it will take that version and ignore the other versions.
In your case when you can run -
mvn dependency:tree -Dverbose -Dincludes=spring-aop
You will notice that in the tree hierarchy version 3.0.0 is coming earlier in comparison to version 3.2.3 , so that's why it is taking version 3.0.0 version for resolving the dependency.
Solution : As a recommended solution to these types of problem is have a proper dependency management in your parent pom.xml file. Like in your case you can have something lik e this :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.3</version>
</dependency>
<dependencies>
</dependencyManagement>
Now no matter what whenever Maven try to resolve the version for spring-aop , it will always consult the dependency management and will use the version defined under dependencyManagement.
For more you can refer here on my blog: how maven resolves dependency conflicts

Eclipse (STS) MVC 3.0.5 + Tiles 2.2.2 project dependency management issue

For some reason I cannot use maven or gradle dependecy management. I am trying to use Tiles with Spring MVC, I get the following Exception on tcserver startup:
java.lang.NoClassDefFoundError: org/apache/tiles/startup/BasicTilesInitializer
Here is my dependencies folder:
Also Eclipse points out this Error in my layout.jsp
The tag handler class for
"tiles:insertAttribute" (org.apache.tiles.jsp.taglib.InsertAttributeTag) was not found on the Java Build
Path
Can anyone point out what am I missing?
You put the SOURCE jars in you project lib folder. But you need to use the normal once with the compiled classes.
tiles-core-2.2.2.jar instead of tiles-core-2.2.2-sources.jar
If you use maven to manage dependency then add below to your pom.
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
Else Download following jars and add it to /WEB-INF/lib
tiles-core.2.2.2.jar
tiles-api.2.2.2.jar
and also add this transitive dependency as tiles use on Slf4j
slf4j-jdk14.1.5.8.jar

Resources