Maven项目的创建及SSM环境的搭建

1.搭建maven环境  这里有两个参数一个是user setting 和 local Respository   user setting 配置maven 的包下的 conifg 目录下的user setting ,注意刚解压的maven 包中的user setting 需要配置本地仓库,和第二个参数的地址相同。

2.创建maven项目 我这种创建方法只限于没有多个模块的项目,但是又多个模块的也没那么难,就是new module 创建模块,指定它的父模块就是配置下面第二张图的parent project,但是只有一个模块的不用配置partent project。

3.配置编译器

点击项目右键properties  点开之后如下图

接下来进行ssm的搭建

1.配置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>jk</display-name>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
 <!-- 配置编码过滤器 -->
 <filter>
  <filter-name>codeFilter</filter-name>
  <filter-class>cn.itcast.util.CodeFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>codeFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 配置核心的servlet -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <servlet>
  <servlet-name>springmvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring-*.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>springmvc</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
</web-app>

2.配制applicationContextl.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:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
       http://www.springframework.org/schema/beans/spring-beans.xsd  
       http://www.springframework.org/schema/context  
       http://www.springframework.org/schema/context/spring-context.xsd  
       http://www.springframework.org/schema/mvc  
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://cxf.apache.org/jaxrs
       http://cxf.apache.org/schemas/jaxrs.xsd">
<context:component-scan base-package="com.student.service"/>
<context:property-placeholder location="classpath:log4j.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
        <property name="username" value="xiemeng" />
        <property name="password" value="xiemeng" />
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    </bean>
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <!--数据库连接池-->
        <property name="dataSource" ref="dataSource" />
        <!--加载mybatis的全局配置文件-->
        <property name="configLocation" value="classpath:SqlMapConfig.xml" />
        <property name="mapperLocations">
        <list>
        <value>com/student/dao/*.xml</value>
        </list>
        </property>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.student.dao" />
    </bean>
</beans>

3.配制spring-mvc.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:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context.xsd  
    http://www.springframework.org/schema/mvc  
http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd
  http://cxf.apache.org/jaxrs
    http://cxf.apache.org/schemas/jaxrs.xsd">
<context:component-scan base-package="com.student.controller"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF"/>
<property name="suffix" value=".html"/>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="mappingJacksonHttpMessageConverter" />
        </list>
    </property>
</bean>
<!-- JSON转换器 -->

<bean id="mappingJacksonHttpMessageConverter"
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    <property name="supportedMediaTypes">
        <list>
            <value>text/html;charset=UTF-8</value>
        </list>
    </property>
</bean>
<mvc:resources location="/js/" mapping="/review/js/**"></mvc:resources>
<mvc:resources location="/css/" mapping="/review/css/**"></mvc:resources>
<mvc:resources 
        location="/jquery-ui-themes-1.12.1/" mapping="/review/jquery-ui-themes-1.12.1/**"> </mvc:resources>
<mvc:view-controller path="/index" view-name="/index"/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
</beans>

4.spring-mybatis.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:mvc="http://www.springframework.org/schema/mvc"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx.xsd ">
 <!-- 配置事务 -->
  <bean id="transactionManager"
   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource" />
  </bean>
  <!-- 配置注解驱动 -->
  <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

配置过程中遇到的问题及解決方式

1.can'  find  ContextLoaderListern can't  find  或者bean is not defined ,这个错误一般是你真的沒定义,或者定义错了,还有一种情況就是 你的maven dependency  沒有引用,通俗点就是jar 包沒有引入classpath 找不到。

点击add 之后配置加入maven dependency,这个破破题,我刚开始没有想到,费了我好长时间

2.canl auto  private interface 这个问题也是我理解不深刻,刚开始的时候在一个文件applicationContext.xml 中配置, 后来分文件配置,它sprngContext 的初始化是有 順序的,他先加載applicationContext 結果我沒有在spingmvc 中配置mapper的映射和掃描,還有数据源,当然找不见了,有的还跟你说springmvc 基于接口配置,要实现set 方法,其實注解不用。

3.no suit driver出现的原因,我认为常遇到的是你的配置有问题,比如说url 写错了。

4.测试的時候,RequestMapping上多了一个/,而在dispatcherServlet中配置的是/,导致404问题,配置*.action也是可以的。則不用去除requestMapping上那个多余的的/

5.还有那个spring-servlet.xml没有加载问题这个你必须在你的<context-param></param> 和<init-param></param>中都配置了就不会出现这个问题。

6.maven 整合springmvc spring myatis整合报错java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]解决方法如下:

<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
7.Intellij idea ssm 整合的话一直 no classdef org\ibitis\session\session  直接清理缓存,或者替换那个多余的文件。


8.spring配置完成后访问404问题或者一般是你的jar包可能有问题,可以看problem中提示的错误,或者查看控制台中有无错误。

9.提示zip is not read problem错误,更换jar 包,build path 清除报错的jar 包,重新下载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值