当前位置:   article > 正文

spring报错笔记_could not autowire. no beans of 'articleservice' t

could not autowire. no beans of 'articleservice' type found.

1.通配符很全面,但无法找到元素***

解决:beans里面导包导错了

2.org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'bookId' in 'class com.aotao.pojo.Books'     在Books中没有找到bookId;

解决:

1.Books类中创建的属性

  1. private int bookID;
  2. private String bookName;
  3. private int bookCounts;
  4. private String detail;

2.BookMapper接口的内容

发现圈红的地方与Books类中的bookID不一致所以报错

 

3.org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.aotao.dao.BookMapper.deleteBookById

很奇葩的错误方法和前面更新一样完全看不出哪里有错误

解决:

既然是没找到方法那可能是某处的方法名称没写对

如下图这里的deleteBookId应该改成deleteBookById要和BookMapper里面的方法名一致

 

 

4.使用@RestController后返回的值找不到页面

代码如下:

  1. @RestController
  2. public class AjaxController {
  3. @RequestMapping("/hello")
  4. public String sayHello(){
  5. return "hello";
  6. }
  7. }

 原因:

在web.xml文件中没有加:

  1. <servlet>
  2. <servlet-name>springmvc</servlet-name>
  3. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  4. <init-param>
  5. <param-name>contextConfigLocation</param-name>
  6. <param-value>classpath:springmvc-servlet.xml</param-value>
  7. </init-param>
  8. <!--启动级别1-->
  9. <load-on-startup>1</load-on-startup>
  10. </servlet>
  11. <!--/ 匹配所有的请求:(不包括.jsp)-->
  12. <!--/* 匹配所有的请求:(包括.jsp)-->
  13. <servlet-mapping>
  14. <servlet-name>springmvc</servlet-name>
  15. <url-pattern>/</url-pattern>
  16. </servlet-mapping>

5.Could not autowire. No beans of 'ArticleService' type found.

注释没写清楚可以看:https://blog.csdn.net/mengltx/article/details/79833322

 

6.Springboot 使用getRequestDispatcher一直循环报错 

拦截器:

  1. public class LoginHandlerInterceptor implements HandlerInterceptor {
  2. @Override
  3. public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  4. //登陆成功之后,应该有用户的session
  5. System.out.println("开始拦截");
  6. Object username = request.getSession().getAttribute("username");
  7. if (username == null){
  8. request.setAttribute("msg","没有权限,请先登陆");
  9. request.getRequestDispatcher("/admin/login.html").forward(request,response);
  10. return false;
  11. }else {
  12. return true;
  13. }
  14. }
  15. }

MvcConfig类

  1. @Configuration
  2. public class MyMvcConfig implements WebMvcConfigurer {
  3. //添加拦截器
  4. @Override
  5. public void addInterceptors(InterceptorRegistry registry) {
  6. //注册TestInterceptor拦截器
  7. System.out.println("是否注册");
  8. InterceptorRegistration registration = registry.addInterceptor(new LoginHandlerInterceptor());
  9. registration.addPathPatterns("/**"); //所有路径都被拦截
  10. registration.excludePathPatterns(
  11. "/**/*.html",
  12. "/**/*.js",
  13. "/**/*.css",
  14. "/**/*.woff",
  15. "/**/*.ttf"
  16. );
  17. }
  18. }

 

 

问题解析:https://blog.csdn.net/A_bad_horse/article/details/105300073

原因:

1. 首次登录会进入:http://localhost:8080/admin/toLlogin页面

2. 接下来拦截器会拦截/admin/toLogin页面判断是否有session

3. 因为没有设置/admin/下面的登陆页面不拦截所以一直重复1-2-1死循环

解决:把/admin/下的index.html不拦截如果没有session的情况下跳转到/admin/index 页面

再把视图控制器加上

  1. @Configuration
  2. public class MyMvcConfig implements WebMvcConfigurer {
  3. @Override
  4. public void addViewControllers(ViewControllerRegistry registry) {
  5. registry.addViewController("/").setViewName("/");
  6. registry.addViewController("/admin/index.html").setViewName("/admin/index");
  7. registry.addViewController("/admin/login.html").setViewName("/admin/login");
  8. }
  9. //添加拦截器
  10. @Override
  11. public void addInterceptors(InterceptorRegistry registry) {
  12. //注册TestInterceptor拦截器
  13. System.out.println("是否注册");
  14. InterceptorRegistration registration = registry.addInterceptor(new LoginHandlerInterceptor());
  15. registration.addPathPatterns("/**"); //所有路径都被拦截
  16. registration.excludePathPatterns(
  17. "/admin/index.html", // 排除system路径下所有文件
  18. "/images/**",
  19. "/**/*.html",
  20. "/**/*.js",
  21. "/**/*.css",
  22. "/**/*.woff",
  23. "/**/*.ttf"
  24. );
  25. }
  26. }

 

7.springboot 整合mybatis时insert语句报错找不到类Mapper method 'com.aotao.springboot.mapper.ArticleMapper.insertArticle' has an unsupported return type: class com.aotao.springboot.domain.Article

aritcle:

  1. package com.aotao.springboot.domain;
  2. import lombok.AllArgsConstructor;
  3. import lombok.Data;
  4. import lombok.NoArgsConstructor;
  5. import java.util.List;
  6. @Data
  7. @NoArgsConstructor
  8. @AllArgsConstructor
  9. public class Article {
  10. private int articleID;
  11. private String articleTitle;
  12. private String content;
  13. private String flag;
  14. private String description;
  15. private String imgUrl;
  16. private String createTime;
  17. private String updateTime;
  18. private int typeID;
  19. }

 

insert:

  1. <insert id="insertArticle" parameterType="Article">
  2. insert into article (articleTitle,content,flag,description,imgUrl,createTime,updateTime,typeID)
  3. values (#{articleTitle},#{content},#{flag},#{description},#{imgUrl},#{createTime},#{updateTime},#{typeID});
  4. </insert>

分析:

报错内容说的是insertArticle 方法返回了不支持的类型

public Article insertArticle(Article article);

返回类型为Article,我发现添加文章操作应该返回的是添加成功了几条而不是一个类型。

所以把返回类型改为int就行了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/946591
推荐阅读
相关标签
  

闽ICP备14008679号