Maven+SpringMVC整合之helloworld
来源:互联网 发布:淘宝助理没有创建宝贝 编辑:程序博客网 时间:2024/05/20 15:41
一、废话
算是一个入门的例子,虽然难度不大,但对于我这种刚接触Maven和SpringMVC的菜鸟来讲还是费了点时间。貌似网上很多教程都是关于在Eclipse下搭建的,不过像我这样的屌丝还是坚持我的Myeclipse之旅吧。Eclipse神马的,=日后再说吧。废话不多说,切入主题。
二、项目搭建流程
都是流程上的东西,记住便可了。下面步骤没有非常细化,自认为比较重要
Step1:
Step2:
控制器Controller编写
- 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配置
- <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
- Maven+SpringMVC整合之helloworld
- Maven+SpringMVC整合之helloworld
- springMVC + maven helloworld程序
- 【springmvc】 springmvc 之 HelloWorld
- 手把手 Spring、SpringMVC、MyBatis 整合教程之 HelloWorld
- SpringMVC+spring+maven整合
- SpringMVC+mybatis+maven整合
- Maven+SpringMVC+MyBatis整合
- maven+springMVC+hibernate整合
- springMVC+hibernate+maven整合
- springmvc-mongodb-maven整合
- springmvc mongodb maven 整合
- SpringMVC+MongoDB+Maven整合
- Maven+SpringMVC+Swagger整合
- maven-springmvc 整合配置
- 怎样理解阻抗匹配
- Asynctask解析以及注意事项
- 看 android omx 源码有感
- Android Studio编码问题
- Oracle分区表用法
- Maven+SpringMVC整合之helloworld
- 三层+存储过程实现分页
- Android ANR
- 自定义标签之五—传统自定义标签与简单自定义标签关于更新页面内容(小写变大写)
- 详解Listener监听Http Session
- Maven环境搭建流程【旧】
- 完美解决IE兼容模式问题
- Javascript 函数对象
- 【高手分享:拼音/五笔输入法通用使用技巧】