如何使用eclipse创建一个jdbc+spring+springmvc项目,本人菜鸟一枚,还望高手指教。

最好是把所需jar能发给我,教教我怎么配置。
2024-11-26 21:51:17
推荐回答(1个)
回答1:

SpringMVC+MyBatis+Freemarker 简单框架搭建(一)

一、开发环境:
Eclipse、Tomcat、SVN等请参见如下的帖子,很详细了。
http://www.iteye.com/topic/982182

svn和maven插件的安装:
1、先安装gef插件
地址:http://download.eclipse.org/tools/gef/updates/interim/
2、安装svn插件
地址:http://subclipse.tigris.org/update_1.6.x
3、maven插件
m2eclipse-core Update 地址: http://m2eclipse.sonatype.org/sites/m2e
m2eclipse-extras Update 地市: http://m2eclipse.sonatype.org/sites/m2e-extras
4、安装可能出现的问题
直接在线安装maven2 会出现依赖插件找不到的问题,无法安装。必须先安装gef 插件后才能安 装m2eclipse-core 插件,然而安装m2eclipse-extras 插件又依赖subclipse 插件。所以,三个插 件的正确的安装顺序是:gef插件 》subclipse插件 》m2eclipse插件

二、web.xml 和 applicationContext.xml 配置
1、web.xml文件配置:

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_2_5.xsd"
version="2.5">


contextConfigLocation
classpath:applicationContext.xml




springServlet
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:contextConfigLocation-springService.xml

0


springServlet
/




org.springframework.web.context.ContextLoaderListener






org.springframework.web.util.IntrospectorCleanupListener




20


index.jsp




Set Character Encoding
org.springframework.web.filter.CharacterEncodingFilter

encoding
GB2312


forceEncoding
true



Set Character Encoding
/



Archetype Created Web Application


节点和节点是web项目启动时最先读取的两个节点,所以这两个节点里面所配置的内容是web项目启动时最先加载的部分。
节点中配置的applicationContext.xml里面主要是数据库的配置信息,以及事务等等
节点配置的是web请求的监听器

2、applicationContext.xml 内容如下:


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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
">









class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">


classpath:jdbc.properties







value="${jdbc.url}">













p:dataSource-ref = "dataSource"
p:configLocation = "classpath:sqlMapConfig.xml" />







p:dataSource-ref = "dataSource" />


p:basePackage = "com.weiluo.example.entity" />






3、web.xml中的节点配置的是与请求处理相关的一些内容,主要是 url路由处理器,视图解析器,等等,如下:

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:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">






class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">






class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">











class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">