搭建maven+spring+freemaker+mybatis环境之二

本文详细介绍了如何使用 Maven 构建 Spring MVC 项目,包括配置 web.xml、spring.xml 和 spring-servlet.xml 文件,以及 pom.xml 中依赖的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里是搭建maven+spring+freemaker+mybatis环境的第二部分,maven+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_2_5.xsd"
	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>Archetype Created Web Application</display-name>
  <context-param>  
        <param-name>log4jConfigLocation</param-name>  
        <param-value>classpath:log4j.properties</param-value>  
    </context-param>  
      
    <filter>
		<filter-name>encodingFilter</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>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
    <listener>  
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
    </listener>
      
    <!--spring 环境准备  -->
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
    
  	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring.xml</param-value>
	</context-param>
  
	<!-- http 请求分发 -->
    <servlet>  
        <servlet-name>webmvct</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-servlet.xml</param-value>
		</init-param>  
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
        <servlet-name>webmvct</servlet-name>  
        <url-pattern>*.htm</url-pattern>  
    </servlet-mapping>  
    
    <!-- 配置session超时时间,单位分钟 -->
	<session-config>
		<session-timeout>15</session-timeout>
	</session-config>
	
    <welcome-file-list>  
            <welcome-file>index.htm</welcome-file>  
    </welcome-file-list>
</web-app>

由最初的web.xml到上面的内容,需要注意的几个问题,

1.修改xml的xmlns  和xsi的版本,因为之前遇到了内部标签顺序颠倒会报错的问题

2.先有ContextLoaderListener,再有DispatcherServlet,而且都有初始化参数,第一个类如果没有初始化参数会报application.xml找不到的错误,他们具体作用,参见网上文档

3.在项目骨架的src/main/resources 文件夹下准备好web.xml里面用到的配置文件log4j.properties,spring.xml,spring-servlet.xml

4.把WEB-INF下的index.jsp换成了index.html

springxml的代码:

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
	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  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    http://www.springframework.org/schema/tx    
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
    ">
   
	
</beans>
spring-servlet.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	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
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
    ">

	<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
	<context:component-scan base-package="com.template" />
	<!-- 默认的注解映射的支持 -->
	<mvc:annotation-driven />


</beans>

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.template.cn</groupId>
  <artifactId>template</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>template Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- spring相关包 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>  
  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>1.2.14</version>  
        </dependency>
  </dependencies>
  <build>
    <finalName>template</finalName>
  </build>
</project>



log4j.properties的代码,网上找的稍微有改动

#root directory for log files
dir=d://Logs
#log file for online
file00=error.log
#log file for batch
file01=debug.log
#log file size
fileSize=10000KB
#back up numbers for log file
backup=10
###########################default log level and log appender###########################
log4j.rootLogger=DEBUG,CONSOLE,SYSFILE
log4j.logger.platform_debug=DEBUG,DEBUGFILE
log4j.logger.platform_error=ERROR,ERRORFILE
log4j.logger.platform_info=INFO,INFOFILE
########################################################################################
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p][%t] method:%l%n    %m%n
########################################################################################
log4j.appender.DEBUGFILE=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.DEBUGFILE.file=\\temp_space\\logs\\platform-debug.log
log4j.appender.DEBUGFILE.file=${dir}/debug.log
log4j.appender.DEBUGFILE.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.DEBUGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUGFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p][%t] method:%l%n    %m%n
########################################################################################
log4j.appender.ERRORFILE=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.ERRORFILE.file=\\temp_space\\logs\\platform-error.log
log4j.appender.ERRORFILE.file=/data/logs/platform-error.log
log4j.appender.ERRORFILE.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.ERRORFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ERRORFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p][%t] method:%l%n    %m%n
########################################################################################
log4j.appender.SYSFILE=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.SYSFILE.file=\\temp_space\\logs\\platform-sys.log
log4j.appender.SYSFILE.file=/data/logs/platform-sys.log
log4j.appender.SYSFILE.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.SYSFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p][%t] method:%l%n    %m%n
########################################################################################
log4j.appender.INFOFILE=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.INFOFILE.file=\\temp_space\\logs\\platform-info.log
log4j.appender.INFOFILE.file=/data/logs/platform-info.log
log4j.appender.INFOFILE.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.INFOFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.INFOFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p][%t] method:%l%n    %m%n
########################################################################################



最后启动,看是否能正常启动


资源下载链接为: https://pan.quark.cn/s/9648a1f24758 这个HTML文件是一个专门设计的网页,适合在告白或纪念日这样的特殊时刻送给女朋友,给她带来惊喜。它通过HTML技术,将普通文字转化为富有情感和创意的表达方式,让数字媒体也能传递深情。HTML(HyperText Markup Language)是构建网页的基础语言,通过标签描述网页结构和内容,让浏览器正确展示页面。在这个特效网页中,开发者可能使用了HTML5的新特性,比如音频、视频、Canvas画布或WebGL图形,来提升视觉效果和交互体验。 原本这个文件可能是基于ASP.NET技术构建的,其扩展名是“.aspx”。ASP.NET是微软开发的一个服务器端Web应用程序框架,支持多种编程语言(如C#或VB.NET)来编写动态网页。但为了在本地直接运行,不依赖服务器,开发者将其转换为纯静态的HTML格式,只需浏览器即可打开查看。 在使用这个HTML特效页时,建议使用Internet Explorer(IE)浏览器,因为一些老的或特定的网页特效可能只在IE上表现正常,尤其是那些依赖ActiveX控件或IE特有功能的页面。不过,由于IE逐渐被淘汰,现代网页可能不再对其进行优化,因此在其他现代浏览器上运行可能会出现问题。 压缩包内的文件“yangyisen0713-7561403-biaobai(html版本)_1598430618”是经过压缩的HTML文件,可能包含图片、CSS样式表和JavaScript脚本等资源。用户需要先解压,然后在浏览器中打开HTML文件,就能看到预设的告白或纪念日特效。 这个项目展示了HTML作为动态和互动内容载体的强大能力,也提醒我们,尽管技术在进步,但有时复古的方式(如使用IE浏览器)仍能唤起怀旧之情。在准备类似的个性化礼物时,掌握基本的HTML和网页制作技巧非常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值