springmvc求解

王子文龙 2015-09-28 04:20:48
在不使用注解的情况下使用springmvc:
在mvc配置文件中只配置controller,在applicationContext配置文件中配置
     <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>

会找不到映射,是什么原因?
...全文
265 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxucchenn 2015-10-10
  • 打赏
  • 举报
回复
应该是web.xml里面没加载把
孙洪亮 2015-09-29
  • 打赏
  • 举报
回复
你试一试在一个配置文件中引入另一个配置文件。是不是没有引入的原因
王子文龙 2015-09-29
  • 打赏
  • 举报
回复
引用 5 楼 fwwer 的回复:
因为你的web.xml里的配置是只加载了其中一个文件吧
不是啊,监听器加载applicationContext,DispatherServlert加载mvc
王子文龙 2015-09-29
  • 打赏
  • 举报
回复
引用 7 楼 hongliang_sun 的回复:
你试一试在一个配置文件中引入另一个配置文件。是不是没有引入的原因
跟引入没关系,这两个配置文件都会被加载,我只是想这样试试看,当然实际开发中不会这样去弄,都用注解了,只是想知道这样为什么不行
王子文龙 2015-09-29
  • 打赏
  • 举报
回复
引用 8 楼 Mozhx 的回复:
如有多个spring配置文件要在web.xml中指定多个文件名
肯定是多个,只是以不同的形式去加载而已
Mozhx 2015-09-29
  • 打赏
  • 举报
回复
如有多个spring配置文件要在web.xml中指定多个文件名
fwwer 2015-09-28
  • 打赏
  • 举报
回复
因为你的web.xml里的配置是只加载了其中一个文件吧
王子文龙 2015-09-28
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
这样看不出来啊。
mvc中的配置

<?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-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/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
     <!-- 
      <mvc:annotation-driven/>
     <context:component-scan base-package="com.metarnet.controller"></context:component-scan>
     -->
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsps/"></property>
        <property name="suffix" value=".jsp"></property>
     </bean>
     <bean id="hello" name="/hello.do" class="com.metarnet.controller.HelloWorldController">
     </bean>
</beans>
applicationContext中的配置

<?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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
      <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
     <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>       
</beans>
分开到两个配置文件中写会找不到映射,而统一写到一个配置文件中可以
王子文龙 2015-09-28
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
这样看不出来啊。
引用 1 楼 salory 的回复:
提半天问也没问出个什么东西,找不到映射的原因太多了嘛,先看看你在applicationContext.xml中配置引入文件没
意思就是上面的那两个bean跟controller分开到mvc以及applicationContext两个配置文件中会找不到映射,而如果不分开,不管是都配置在mvc还是applicationContext中都可以找到映射
tony4geek 2015-09-28
  • 打赏
  • 举报
回复
这样看不出来啊。
salory 2015-09-28
  • 打赏
  • 举报
回复
提半天问也没问出个什么东西,找不到映射的原因太多了嘛,先看看你在applicationContext.xml中配置引入文件没

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧