Maven+SpringMVC整合之helloworld
2013-06-25 17:08
531 查看
一、废话
算是一个入门的例子,虽然难度不大,但对于我这种刚接触Maven和SpringMVC的菜鸟来讲还是费了点时间。貌似网上很多教程都是关于在Eclipse下搭建的,不过像我这样的屌丝还是坚持我的Myeclipse之旅吧。Eclipse神马的,=日后再说吧。废话不多说,切入主题。二、项目搭建流程
都是流程上的东西,记住便可了。下面步骤没有非常细化,自认为比较重要
Step1:
Step2:
控制器Controller编写
[java]
view plaincopyprint?
package com.techbirds.web.controller; import java.util.Map; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller @Scope("prototype") public class HelloContorller { //hello world例子 @RequestMapping(value="/hello") public String hello(){ System.out.println("spring mvc hello world!"); return "hello"; } }
package com.techbirds.web.controller; import java.util.Map; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller @Scope("prototype") public class HelloContorller { //hello world例子 @RequestMapping(value="/hello") public String hello(){ System.out.println("spring mvc hello world!"); return "hello"; } }
Step3:
maven项目的pom.xml配置
[html]
view plaincopyprint?
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.techbirds.web</groupId> <artifactId>springmvc-hello</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springmvc-hello Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <org.slf4j-version>1.6.1</org.slf4j-version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.5_spec</artifactId> <version>1.2</version> </dependency> </dependencies> </project>
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.techbirds.web</groupId> <artifactId>springmvc-hello</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springmvc-hello Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <org.slf4j-version>1.6.1</org.slf4j-version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.5_spec</artifactId> <version>1.2</version> </dependency> </dependencies> </project>
Step4:
使用外部tomcat部署,方便debug。不过必须每次依赖配置后,redeploy一下,否则依赖的包更新不到tomcat下。
这里顺便记录下:
因为多个spring版本一起时造成的异常:
java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add
运行成功:hello world!
相关文章推荐
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- Spring 3 MVC Framework Based Hello World Web Application Example Using Maven, Eclipse IDE And Tomcat
- Spring 3 mvc hello world application with maven and jstl
- http://crunchify.com/simplest-spring-mvc-hello-world-example-tutorial-spring-model-view-controller-tips/ 非常棒的spring入门,maven,以及eclipse
- springMVC + maven helloworld程序
- SpringMVC学习笔记(二)使用IntelliJ IDEA开发Spring MVC HelloWorld(基于Maven)
- Eclipse中Maven+Spring3.2.17+SpringMVC HelloWorld
- SpringBoot Helloworld 测试 Maven项目
- Hello World Spring MVC Hello World
- 用Maven整合SpringMVC+Spring+Hibernate 框架,实现简单的插入数据库数据功能(二)
- SpringMVC+Spring+Mybatis+Maven整合-使用的工具
- 关于spring+springmvc+mybatis+maven的框架整合实例
- 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例
- Spring MVC hello world annotation example
- Maven+SpringMVC整合之helloworld
- Dubbo整合maven+spring+springmvc+mybatis
- SpringMvc+Spring+Mybatis+Maven整合