org.springframework.web.servlet not found in maven - spring

I am trying to download the org.springframework.web.servlet using maven dependency
but maven could not download it.i want to know is this dependency is there in maven or not
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web.servlet</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
or spring has changed its dependency or can we use some alternate dependency for it.please suggest

The package org.springframework.web.servlet is contained in the spring-webmvc module. Use this dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>`
Update: Since this post is quite old, please check for newer versions of the spring framework. Release 3.1.1.RELEASE is quite out-dated.

Related

Spring 4 does not import EhCache

While migrating a project from Spring 3 to Spring 4 (using IntelliJ and Maven), I encountered a problem with this imported EhCache package:
Error:(13,40) java: error: package org.springframework.cache.ehcache does not exist
Analyzing the problem, I found that Spring 3 was importing the ehCache package from spring-context-support which is included with maven's spring-core dependency.
Spring 4's spring-core does not include the spring-context-support which contains the ehcache package, so I manually added to the POM the dependency for spring-context-support as such:
pom.xml
<spring.version>4.3.25.RELEASE</spring.version>
<ehcache.version>2.5.0</ehcache.version>
(...)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
(...)
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${ehcache.version}</version>
</dependency>
However, the dependency is not being imported at all. Only the spring-context lib gets imported which does not contain the ehCache package:
Spring 3:
Spring 4
Things I've tried:
mvn clean install
using IntelliJ to re-import maven dependencies
deleting .idea folder and restarting IntelliJ to force dependency imports
deleting the .m2 folder
What am I doing wrong here? How do I use EhCache with spring 4 and maven?
I think for ehcache the dependency should be
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.8.1</version>
</dependency>
when you check here, it indicates that the artifact has been moved to the one mentioned above.
The most likely explanation is that you Maven setup is not correct.
Could you run mvn dependencies:tree in the project where you added spring-context-support version 4.3.25?
That will tell you whether or not Maven sees that dependency.
If it does not, I would check which file you edited vs. which project you are testing.

get all dependencies with versions in spring-context 4.3.6.Release

How to get the list of all dependencies with versiosn used in spring-context 4.3.6 Release ? I do see that for spring boot in spring.io page but not for spring-context
If you are using maven adding this will resolve all dependencies
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
It has following dependencies:
org.springframework:spring-context:4.3.6.RELEASE
org.springframework:spring-aop:4.3.6.RELEASE
org.springframework:spring-beans:4.3.6.RELEASE
org.springframework:spring-core:4.3.6.RELEASE
commons-logging:commons-logging:1.2
org.springframework:spring-expression:4.3.6.RELEASE

maven spring library correct dependency

Let's say I am creating a new project, maven based, and I want to use spring 4.2.3.RELEASE.
I also want to use spring-test and spring security and X, Y and Z.
How can I know for sure what exact versions to add in maven to avoid conflicts?
Thanks
later edit:
can this help me?
Maven "Bill Of Materials" Dependency
It is possible to accidentally mix different versions of Spring JARs when using Maven. For example, you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release. If you forget to explicitly declare a direct dependency yourself, all sorts of unexpected issues can arise.
To overcome such problems Maven supports the concept of a "bill of materials" (BOM) dependency. You can import the spring-framework-bom in your dependencyManagement section to ensure that all spring dependencies (both direct and transitive) are at the same version.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
An added benefit of using the BOM is that you no longer need to specify the <version> attribute when depending on Spring Framework artifacts:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependencies>
You are right, the BOM is one of the most powerfull ways to fight (even maven based) dependency hell.

How do I find the library containing org.springframework.stereotype.Service?

Trying to import import org.springframework.stereotype.Service; I get cannot resolve symbol stereotype. As I understand it, I should be able to get the required dependency using Maven.
However... how do I find out which dependency to get -- i.e. the name of the dependency? That is, which library contains this library and how would I go about finding out?
Thanks!
It's the spring-context jar that your need. Add the following to your maven dependencies..
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
This example is referencing the latest version of the jar available at the moment but you should match the version with the version of spring that you want.
You can use this site : http://www.findjar.com/
Just past your class name (entire path org.spri...)
You need to import this dependency in Maven:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
Note that the version number can be omitted if you use the parent module of Spring Boot:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
where 1.4.3.RELEASE is the latest version of Spring Boot.
Google search
org.springframework.stereotype.Service jar
and then do a search here for the maven dependency configuration
Make sure you create DynamicWebProject, if you are using a Java Project and added that Maven dependency it would not work. Anyway, you dont need a separate dependency, its part of the spring-context already
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>

What is the name of spring-webmvc on Spring Enterprise Bundle Repository?

Are spring-webmvc on Maven and org.springframework.web.servlet on EBR the same? I can't seem to find spring-webmvc on Spring's EBR.
Maven:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
Spring EBR:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web.servlet</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
According to the official Spring documentation, the bundle's symbolic name is derived from the main package root, e.g. org.springframework.beans or org.springframework.web.servlet. Since one of the core classes of Spring MVC, i.e. org.springframework.web.servlet.DispatcherServlet, sits in the org.springframework.web.servlet package, the bundle is named org.springframework.web.servlet.

Resources