MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

 时间:2024-10-22 17:47:28

1、创建一个maven项目如图:

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目
MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

2、项目创建完毕后整体架构如图:

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

3、配置web.xml文件:<?xml version="1.0" e艘绒庳焰ncoding="UTF幻腾寂埒-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>website</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.json</url-pattern> </servlet-mapping> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>WEB-INF/jsp/MyJsp.jsp</welcome-file> </welcome-file-list></web-app>

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

4、配置dispatcher-servlet.xml文件:<?xml version="1.0" encoding=&鳎溻趄酃quot;UTF-8"?><beans xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-autowire="byName" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <context:annotation-config/> <context:component-scan base-package="com"> </context:component-scan> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <ref bean="mappingJacksonHttpMessageConverter"/> </property> </bean> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <!-- ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="requestContextAttribute" value="rc" /> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans>

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

5、配置applicationContext.xml文件:<?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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName"> <context:annotation-config/> <context:component-scan base-package="com"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> <import resource="conf/spring/*.xml"/> </beans>

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目

6、写一个程序跑一下项目结果如下,大功告成:

MyEclipse10搭建MavenSpringMVC注解JavaWeb项目
MyEclipse10搭建MavenSpringMVC注解JavaWeb项目
  • Mysql 错误:cannot create windows service
  • 怎么创建maven项目
  • 如何查看Mysql是否已经安装?
  • 怎样使用Eclipse新建Android模拟器
  • 如何解决myeclipse导入工程出现错误
  • 热门搜索
    古诗配画手抄报 手抄报初中生 放飞梦想手抄报素材 诚信的手抄报图片 爱护动物手抄报 青春期手抄报 关于爱国的手抄报内容 手抄报怎么画 预防流感手抄报 关于环保的手抄报图片