日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Eclipse利用Maven2搭建SpringMVC框架的Web工程

發(fā)布時間:2023/12/9 javascript 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eclipse利用Maven2搭建SpringMVC框架的Web工程 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、準(zhǔn)備工作:

  下載apache-maven--> 配置Maven_home -->下載Eclipse Maven插件

二、新建工程:

   ? 選擇新建Maven Project ?archetype選擇webapp-->輸入group ID (src下包名)和Artifact ID (工程名)

新建Maven工程目錄如上圖

三、補齊缺失的文件夾:

? ? ? ? ? 添加Server支持和缺失的源文件夾

四、添加springMvc支持和web容器支持(若沒有,打包時會報錯)

<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.maven.my</groupId><artifactId>TestMaven2</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>TestMaven2 Maven Webapp</name><url>http://maven.apache.org</url>

<properties>
<spring.version>4.1.5.RELEASE</spring.version>
</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-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency></dependencies><build><finalName>TestMaven2</finalName></build> </project>

(五)修改工程配置:

?在以上兩個文件中修改jdk版本為1.7以上 web為3.0

六:添加springMvc配置:

web.xml

<?xml version="1.0" encoding="UTF-8"?><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_3_0.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="study" version="3.0"><display-name>Archetype Created Web Application</display-name><description>sprintMVC環(huán)境搭建</description><!-- 加載Spring配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:configs/beans.xml</param-value></context-param><!-- Spring監(jiān)聽 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Spring MVC配置 --><servlet><servlet-name>Dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 自定義spring mvc的配置文件名稱和路徑 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:configs/beans-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- spring mvc 請求后綴 --><servlet-mapping><servlet-name>Dispatcher</servlet-name><url-pattern>/</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>

src/com/main/resources文件夾下的beans.xml和beans-mvc.xml

beans.xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" > <context:property-placeholder /><context:annotation-config /></beans> <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:property-placeholder /><!-- MVC控制類掃描 --><context:component-scan base-package="com.my.controller" /><mvc:annotation-driven /><!-- 視圖解析器:定義跳轉(zhuǎn)的文件的前后綴 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/view/" /> <property name="suffix" value=".html" /> <!--可為空,方便實現(xiàn)自已的依據(jù)擴展名來選擇視圖解釋類的邏輯 --> </bean> <mvc:default-servlet-handler /> </beans>

七:補齊自己的controller

package com.my.controller;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;@Controller @RequestMapping("/user") public class UserController {@RequestMapping(value="/getUserInfo")public String getUserInfo(HttpServletRequest request){System.out.println("==========");return "user";} }

八:部署運行,輸入http://localhost:8180/TestMaven2/user/getUserInfo訪問。

------------------------------------------------------------------------------------------------------------------------------

一段可能會用到代碼:maven依賴無法加入到工程時,在.classpath添加,很有用

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"><attributes><attribute name="maven.pomderived" value="true"/><attribute name="org.eclipse.jst.component.nondependency" value=""/></attributes></classpathentry>

?

轉(zhuǎn)載于:https://www.cnblogs.com/liangblog/p/5138415.html

總結(jié)

以上是生活随笔為你收集整理的Eclipse利用Maven2搭建SpringMVC框架的Web工程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。