I need some help with setting up a spring project. I am busy going through the book “Spring in action” and I need to try some of the examples out. I have looked at plenty of pages and nowhere can is see where I am going wrong. It must be something silly that I missed or overlooked.
The outline of the project looks as follows
I created my beans (vwCar & nissanCar that implements car interface) and where it comes to use them I have a main method in the app class. I need to create an application context.
ApplicationContext context = new ClassPathApplicationContext("src/main/resources/applicationContext.xml");
But I have difficulty creating the ApplicationContext. It gives me an error and code assist don’t work
Using code assist the only thing that it suggests is (Pressing Ctrl+Space after typing app):
If I just type it out I get an error
ApplicationContext cannot be resolved to a type in class App.java
Is there something that I should import myself?
I can see an "S" on the project folder - doesn't this indicate that the project is already spring enabled?
---------ADDED AFTER ALEX COMMENTED TO SUGGEST THAT I SHOULD ADD A MAVEN DEPENDENCY-------------
I added the missing dependency like Alex suggested but I don't know what the correct version is. If I look a the STS directory I see several files named ... 2.9.2
org.springframework.ide.eclipse.feature_2.9.2.201205070117-RELEASE
but if I add the dependency with 2.9.2 i get the following error on my POM
Missing artifact org.springframework:spring-context:jar:2.9.2
My POM looks like below
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.chrispie</groupId>
<artifactId>MyMavenSpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyMavenSpringProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</project>
Since you're using Maven you should add the following dependency to your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
Where ${org.springframework-version}
should be replaced with the version you are using.
This will ensure that the Spring jars needed to get started are available to your application.
It must be something silly that I missed or overlooked.
I think you'v just overlooked the dependency management functionality of Maven. Creating a Java/Maven project doesn't pull in the required Spring jars. If you used a template project from the STS landing page this would all have been setup for.