Role of spring-aspects jar in AOP? - java

I have following dependencies using in my pom
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${version.spring}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${version.spring}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${version.aspectj}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${version.aspectj}</version>
</dependency>
I ready couple of tutorial on net but no one says to include spring-aspects dependency. I am not sure what role does it way in applying aspects.
Can someone explain why we need spring-aspects ?
Also as per mine understanding spring load time weaving is based on proxy . Javagent does not play any role here. Right ?

It increases Spring AOP functionalities I'd say one of the most common use is to add #Configurable tag that usually is used (but not necessarily )to allow DAO to access the Data Access Layer.
This JAR is a small library of AspectJ that is included in Spring.

Related

Is there a way in POM to specify a higher version for dependent package?

I am using Maven to set up dependency in my app.
I am using Spring Boot v2.1.12.RELEASE which brings in Spring Core v5.1.13.
But there also a library Spring Integration v5.1.9 (which is latest) and brings Spring Core v5.1.11.RELEASE
As you can see that I want Spring Integration to not resolve to v5.1.11 of Spring Core as it has some vulnerabilities.
Is there any way to specify in POM for Spring Integration to resolve to 5.1.13 of Spring Core (instead of 5.1.11) ?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>5.1.9</version>
</dependency>
P.S I do not want to upgrade to the latest release of Spring Boot.
Use maven exclusion tag to exclude the transitive dependency, make sure the excluded library is directly added to pom or it's pulled in by some other dependency.
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>5.1.9</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.11.RELEASE</version>
</exclusion>
</exclusions>
</dependency>
DISCLAIMER: This is just a work around solution for your immediate need, use it only when no other options are possible as managing spring managed dependencies ourself is not maintainable in long run.
I used the recommendation in the post Dependency Management to overcome my challenge.
So I excluded the spring-core dependency from spring integration and also added the spring core library using below code
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.13.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>

I am confused with maven dependencies: "org.eclipse.persistence.jpa" and "org.hibernate"

I have a Spring MVC project using Maven.
I am using Spring-data-jpa as one of my dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.5.RELEASE</version>
</dependency>
Spring-data-jpa provides the api.
Therefore, I need to add another dependency which implements jpa. However, I am confused about:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.6.4</version>
</dependency>
and
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.4</version>
</dependency>
What is eclipse.persistence? And the difference with hibernate?
Please help!
Eclipse Persistence (EclipseLink) and Hibernate are both implementations of Java Persistence API, each with their own extra features and often their own bugs. In terms of speed, they're very similar to each-other, compared to the other implementations.
Only one of is used in each persistence unit, defined in META-INF/persistence.xml. Look at yours, inside the persistence-unit->provider node you will find the class that is used.
If it starts with org.hibernate, then you can safely remove the eclipse dependency.
If it starts with org.eclipse, you can remove the hibernate dependency.
If you have multiple persistence units, each one can use a different implementation/provider.

cannot access org.springframework.core.env.EnvironmentCapable

I'm trying to get a spring bean in a web application using it:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
AClass aClass = (aClass) wac.getBean("aClass");
And, when I run compile/test/package with maven, an error occurs:
cannot access org.springframework.core.env.EnvironmentCapable
[ERROR] class file for org.springframework.core.env.EnvironmentCapable not found
The most strange is that org.springframework.core.env.EnvironmentCapable exists! :/
Basic Project Configuration:
Spring 3.1.1.RELEASE (There isn't other spring version in classpath)
Maven 3
JSF 2.1
Servlet API 2.5
Any idea is welcome!
Finally, I've solved it! :)
In the pom.xml file, I had to define the scope of spring's dependencies to compile. (Yes, I know that is the default scope of dependencies but for some reason maven was not capable of the job). See a piece of my pom.xml that made the problem disapear:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
Note that:
If you're having this problem, make sure that you're using a spring
version 3.1 or higher.
Remember that ${spring.version}, in my case, is 3.1.1.RELEASE.
I hope that it helps more people.
I was facing the exact same issue, maven complains from org.springframework.core.env.EnvironmentCapable, even with the file there, inside the jar: C:\Users\fabio\.m2\repository\org\springframework\spring-core\4.3.12.RELEASE\spring-core-4.3.12.RELEASE.jar.
The solution im my case was delete the .m2 folder, so maven downloaded all the jars again. Maybe it was some currupted file.
I hope it helps some one!
Me too face this issue. I used Spring 4.1.6 with maven 3 along with RabbitMQ.
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.1.4.RELEASE</version>
</dependency>
This dependency forced tomcat to die and showing these issue. I havn't gotten why it is making trouble. but finally I explicitly include jar in lib folder and this is how I resolved this issue.
Add this dependency to the pom.xml .You can fixed it.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
As I imported a project from GitHub without checking its spring-boot version had caused me the same problem, thus changing spring-boot version has resolved my problem, I was using version 1.1.4 moving to 2.2.5 (or latest releases ) will download all the needed dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Java - Spring AOP on Eclipse?

I need to use AOP of Spring in Eclipse. So I tried to use '#Aspect' annotation, but it does not found it and just suggest me to create myself. As I understand Spring itself does not have this annotation? Because in documentation it shows that is uses aspectj. So I downloaded from http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/aspectj-1.7.4.jar
Then added it as external jar from project properties. But still nothing changed. Did I miss something?
Update:
I also installed AJDT via plugin manager, but still it does not recognize '#Aspect' annotation. So what should I do so it would recognize it?
You are right, you need both the aspectj plugin and the spring aspect plugins.
First, make sure you have the proper maven dependencies in your project. It should be:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${version}</version>
</dependency>
And modify the versions by the ones you would like to use.
Then if you use a maven plugin for Eclipse like m2e it should find the dependencies.
Hope that helps

Bringing spring-data-jpa into a project causes Spring to stop processing #RequestMapping annotations

I have a Maven/Java project using Spring 3.2.5.RELEASE, which uses component scanning to pick up an #Controller with a number of #RequestMapping annotations and set up the appropriate endpoints.
As soon as I bring in a dependency on spring-data-jpa 1.4.1.RELEASE, the mappings stop being wired up (although the server still starts up without any errors).
The problem is that when you add spring-data-jpa 1.4.1.RELEASE to the pom.xml, it download spring-orm-3.1.4 and others 3.1.4 dependencies. Those Dependencies are incompatible with 3.2.5 so you need do download manually.
To solve the problem you need to say maven to use the correct dependencies. ie. put in the pom.xml the next dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>

Categories

Resources