Skip to content

Commit cf05c91

Browse files
committed
spring root context
spring root context
1 parent a22bfab commit cf05c91

File tree

9 files changed

+258
-0
lines changed

9 files changed

+258
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
4+
<classpathentry kind="src" path="src/main/java" including="**/*.java"/>
5+
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
6+
<classpathentry kind="output" path="target/classes"/>
7+
<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar"/>
8+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
9+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/4.0.0.RELEASE/spring-core-4.0.0.RELEASE.jar"/>
10+
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
11+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar"/>
12+
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
13+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/4.0.0.RELEASE/spring-aop-4.0.0.RELEASE.jar"/>
14+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/4.0.0.RELEASE/spring-beans-4.0.0.RELEASE.jar"/>
15+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/4.0.0.RELEASE/spring-context-4.0.0.RELEASE.jar"/>
16+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/4.0.0.RELEASE/spring-expression-4.0.0.RELEASE.jar"/>
17+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-webmvc/4.0.0.RELEASE/spring-webmvc-4.0.0.RELEASE.jar"/>
18+
<classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-mapper-asl/1.9.12/jackson-mapper-asl-1.9.12.jar"/>
19+
<classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-core-asl/1.9.12/jackson-core-asl-1.9.12.jar"/>
20+
<classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar"/>
21+
<classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
22+
</classpath>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.hmkcode</groupId>
6+
<artifactId>spring-mvc-root-webapplicationcontext</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>spring-mvc-root-webapplicationcontext</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<spring.version>4.0.0.RELEASE</spring.version>
15+
<junit.version>4.11</junit.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-core</artifactId>
22+
<version>${spring.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-web</artifactId>
27+
<version>${spring.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework</groupId>
31+
<artifactId>spring-webmvc</artifactId>
32+
<version>${spring.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>javax.servlet</groupId>
36+
<artifactId>servlet-api</artifactId>
37+
<version>2.5</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.codehaus.jackson</groupId>
41+
<artifactId>jackson-mapper-asl</artifactId>
42+
<version>1.9.12</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.codehaus.jackson</groupId>
46+
<artifactId>jackson-core-asl</artifactId>
47+
<version>1.9.12</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>junit</groupId>
52+
<artifactId>junit</artifactId>
53+
<version>${junit.version}</version>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
57+
58+
<build>
59+
<finalName>spring-mvc-regex</finalName>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.eclipse.jetty</groupId>
63+
<artifactId>jetty-maven-plugin</artifactId>
64+
<version>9.2.2.v20140723</version>
65+
</plugin>
66+
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.1</version>
71+
<configuration>
72+
<source>1.7</source>
73+
<target>1.7</target>
74+
</configuration>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.hmkcode.spring.beans;
2+
3+
public class RootBean {
4+
5+
@Override
6+
public String toString() {
7+
return "RootBean";
8+
}
9+
10+
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.hmkcode.spring.controllers;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
import org.springframework.web.bind.annotation.ResponseBody;
9+
10+
import com.hmkcode.spring.beans.RootBean;
11+
12+
13+
14+
@Controller
15+
@RequestMapping("/controller")
16+
public class MyController {
17+
18+
public MyController(){
19+
System.out.println("new Controller");
20+
}
21+
22+
@Autowired
23+
ApplicationContext context;
24+
25+
@RequestMapping(value = "/get", method = RequestMethod.GET)
26+
public @ResponseBody String get() {
27+
28+
RootBean rootBean = (RootBean) context.getBean("rootBean");
29+
System.out.println(rootBean);
30+
31+
return rootBean.toString();
32+
}
33+
34+
}
35+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:context="http://www.springframework.org/schema/context"
3+
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7+
http://www.springframework.org/schema/context
8+
http://www.springframework.org/schema/context/spring-context-3.0.xsd
9+
http://www.springframework.org/schema/mvc
10+
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
11+
12+
<context:component-scan base-package="com.hmkcode.spring.controllers" />
13+
<mvc:annotation-driven />
14+
</beans>
15+
16+
17+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:context="http://www.springframework.org/schema/context"
3+
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7+
http://www.springframework.org/schema/context
8+
http://www.springframework.org/schema/context/spring-context-3.0.xsd
9+
http://www.springframework.org/schema/mvc
10+
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
11+
12+
13+
<bean class="com.hmkcode.spring.beans.RootBean" name="rootBean" />
14+
</beans>
15+
16+
17+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
3+
<display-name>SpringMVC</display-name>
4+
<welcome-file-list>
5+
<welcome-file>index.html</welcome-file>
6+
</welcome-file-list>
7+
8+
<!-- ROOT WebApplicationContext -->
9+
<context-param>
10+
<param-name>contextConfigLocation</param-name>
11+
<param-value>/WEB-INF/root-context.xml</param-value>
12+
</context-param>
13+
<listener>
14+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
15+
</listener>
16+
17+
<!-- WebApplicationContext -->
18+
<servlet>
19+
<servlet-name>rest</servlet-name>
20+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
21+
</servlet>
22+
23+
<servlet-mapping>
24+
<servlet-name>rest</servlet-name>
25+
<url-pattern>/rest/*</url-pattern>
26+
</servlet-mapping>
27+
</web-app>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5+
<title>Root Context</title>
6+
7+
8+
</head>
9+
10+
<body>
11+
<a href="/rest/controller/get" >Call Controller</a>
12+
</body>
13+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.hmkcode.spring;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)