springmvc自动扫描器初始化异常问题

面向对象的老王 2016-06-29 11:17:47
用springmvc,为什么一用注解扫描器就抛初始化异常,单独注入那个注解类就可以?我用的是eclipse4.5,查了一晚上还是没弄出来
...全文
374 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
何铁 2016-07-21
  • 打赏
  • 举报
回复
感觉的你springmvc 这个配置文件也是有点问题,spring mvc这个配置文件只是用来构建你这个web应用的,你想要使用spring的依赖注入应该配置bean的配置文件。这个资料你可以来这里看看http://jinnianshilongnian.iteye.com/blog/1752171写的挺全的
何铁 2016-07-21
  • 打赏
  • 举报
回复
你再配置一个spring的容器,再web.xml文件里面spring容器的配置加载进去
wyer_ly 2016-07-21
  • 打赏
  • 举报
回复
把classpath下的文件目录写正确。 记得扫描的包的路径尽量往classpath目录的位置配置。
w1530520334 2016-07-21
  • 打赏
  • 举报
回复
<context:component-scan base-package="cn.wyl.springmvc.first.*"/> 试试 我猜的哈。
gdq593192789 2016-07-08
  • 打赏
  • 举报
回复
楼主试下将 下面代码中的<!-- <mvc:annotation-driven /> -->  打开试下 <!-- 使用spring组件扫描 --> <context:component-scan base-package="cn.wyl.springmvc.first"/> <!-- <bean class="cn.wyl.springmvc.first.ItemController3"></bean> --> <!-- <mvc:annotation-driven /> -->
  • 打赏
  • 举报
回复
引用 26 楼 recruits的回复:
ItemController3.java类签名上有以下两个注解么?

@Controller
@RequestMapping
有的
recruits 2016-07-04
  • 打赏
  • 举报
回复
ItemController3.java类签名上有以下两个注解么?

@Controller
@RequestMapping
  • 打赏
  • 举报
回复
来人啊
  • 打赏
  • 举报
回复
来个人啊,困扰我好多天了
渣老王的渣哇 2016-07-02
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
真不好意思,随后马上贴图。这两天在上课。
  • 打赏
  • 举报
回复
来人啊
  • 打赏
  • 举报
回复


这个是包,是因为包冲突吗?不能啊。我在myeclipes能运行
  • 打赏
  • 举报
回复
<context:component-scan base-package="cn.wyl.springmvc.first"/>把这句注释 <!-- <bean class="cn.wyl.springmvc.first.ItemController3"></bean> -->把这句打开就好用 也就是不用扫描器,自己手动注入就好用
渣老王的渣哇 2016-07-01
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
求提示哪里引起的异常,还是初始化异常,只要访问就报异常
  • 打赏
  • 举报
回复
类所在的包
  • 打赏
  • 举报
回复
springmvc.xml的配置 <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.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.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 "> <!-- 配置Handler 由于使用了BeanNameUrlHandlerMapping处理映射器,name配置为url --> <bean name="/itemList.action" class="cn.wyl.springmvc.first.ItemController1" /> <!-- handler2 --> <bean id="itemController2" class="cn.wyl.springmvc.first.ItemController2"></bean> <!-- 使用spring组件扫描 --> <context:component-scan base-package="cn.wyl.springmvc.first"/> <!-- <bean class="cn.wyl.springmvc.first.ItemController3"></bean> --> <!-- <mvc:annotation-driven /> --> <!-- 注解映射器 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <!--简单url映射 集中配置bean的id对应 的url --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/itemsTest2.action">itemController2</prop> </props> </property> </bean> <!-- 配置处理器适配器 springmvc框架根据HandlerAdapter接口判断是否是处理器适配器 --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <!-- HttpRequestHandlerAdapter适配器 --> <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" /> <!-- 注解适配器 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> <!-- ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
渣老王的渣哇 2016-07-01
  • 打赏
  • 举报
回复
继续啊
  • 打赏
  • 举报
回复
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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>springmvc004</display-name> <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:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
加载更多回复(12)

67,513

社区成员

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

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