spring mvc学习

我用的是maven

在web.xml中加入

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

我导入之后报了class not found 后来删除了tomcat 指定好了代码编译后的路径之后 突然好了

然后添加spring需要加载的xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

在applicationcontext中加入

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
                <!-- <value>classpath:cache.properties</value> -->
                <!-- <value>classpath:redis.properties</value> -->
                <!-- <value>classpath:jdbc-mysql.properties</value> -->
                <!-- <value>classpath:itunes-url.properties</value> -->
</list>
</property>
</bean>

目的是把一些配置放进单独的文件中去   这样 在beans文件中就可以使用${属性名}的方式给beans赋值 了


在web.xml中

加入

<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-boost-popular.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

目的是让spring去管理所有的请求

然后就可以使用注解来管理请求了 关于注解的东西:网上有很多

如果是让某些请求返回json什么的一定记得导入jar包

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.2</version>
</dependency>

因为spring通过这个jar包把返回值转换为json




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值