Spring Setting

Spring 会 根据版本不同所要求的 lib 都不一样。。 请认真确认下

建完project  第一个要看的就是 web.xml


红色字体:  file名 根据不同请自行变动 

褐色字体: 变数名 可以有不同

紫色字体: controller 接近ext

灰色底部: 我的spring是 3.0.7relase 如果你的lib 不一样这里也会有所不同 请注意


前奏: 自行下载所需lib http://www.springsource.org/download/community


第一步 驱动tomcat时要读的file 写上  ==> 位置 web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/applicationContext.xml</param-value> 
</context-param>
  
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


第二步 Controller 接近方式 ==> 位置 web.xml

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
 /WEB-INF/conf/action-servlet.xml
</param-value>
 </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
  

第三步 contextConfigLocation  位置 ==>  /WEB-INF/conf/applicationContext.xml ( 有关spring 设置的 就在这里设置了)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
 
    
    <!-- 内容可以没有 -->
</beans>


第四步 action 位置 => /WEB-INF/conf/action-servlet.xml ( 有关 controller 就在这里设置了)


<?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"
  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:component-scan base-package="main">
       <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

</beans>


运行tomcat  如果没有error  恭喜你 spring初步设置完成啦 






 

转载于:https://www.cnblogs.com/xinyuyuanm/archive/2013/04/05/3000861.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值