新手注意的问题

package cn.ryq.web.controller;

import cn.ryq.domain.company.Company;
import cn.ryq.service.company.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import java.util.Date;
import java.util.List; @Controller
@RequestMapping("/system/company")
public class CompanyController {
@Autowired
public CompanyService companyService; @RequestMapping("/list.do")
public ModelAndView list(){
List<Company> list = companyService.findAll();
ModelAndView mv= new ModelAndView();
mv.addObject("list",list );
mv.setViewName("company/company-list");
return mv;
}
}
在确保ApplicationContext-service.xml,有扫包(可以通过右边的小叶子图标来查看是否有扫到包)CompanyController控制器中有@Controller,再检查web.xml的配置,
一般情况下我们都是用多个模块去完成一个项目,那么web.xml的context-param就如下配置,
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext-*.xml</param-value>
</context-param>
还有注意监听器的配置,很多新手对这个配置不熟练,会忘记配置~
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
加载配置文件的路径加*,让web可以扫到整个项目的配置文件!

补充点:发现有些同学的pojo类中没有get和set方法,这会导致数据库无法获取到数据,更加无法自动注入了
如果还有更多问题欢迎来访,相互学习成长,谢谢!

@Autowired自动注入失败的更多相关文章

  1. Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。

    1 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creat ...

  2. SpringAOP导致@Autowired依赖注入失败

    之前用springAOP做了个操作日志记录,这次在往其他类上使用的时候,service一直注入失败,找了网上好多内容,发现大家都有类似的情况出现,但是又和自己的情况不太符合.后来总结自己的情况发现:方 ...

  3. Spring 注解Autowired自动注入bean异常解决

      错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined ...

  4. springboot+mybatis遇到BUG:自动注入失败

    今天用springboot+mybatis写一个小demo遇到如下错误 Error starting ApplicationContext. To display the conditions rep ...

  5. @Autowired注解注入失败,提示could not autowire的解决办法

    autowire异常主要由三个情况发生的 像上面的情况是BrandDao没有注入, 1.你的BrandServiceImpl必须以@Service或@Component注解才行. 2.自动写入的时候把 ...

  6. java-普通类文件@Autowired自动注入为null

    @Autowired注解在非Controller中注入为null 1.配置文件(类文件所在的包) <context:component-scan base-package="net.n ...

  7. Action中如何通过@Autowired自动注入spring bean ?

    1.讲Action纳入spring的IOC控制 <!-- 采用注解方式自动扫描装配 --> <context:component-scan base-package="co ...

  8. SpringBoot中普通类无法通过@Autowired自动注入Service、dao等bean解决方法

    无法注入原因: 有的时候我们有一些类并不想注入Spring容器中,有Spring容器实例化,但是我们又想使用Spring容器中的一些对象,所以就只能借助工具类来获取了 工具类: package com ...

  9. 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...

随机推荐

  1. Open SSL 开发环境配置

    Open SSL 开发环境配置 最后更新日期:2014-05-13 阅读前提:VisualStudio的基本使用.Cent OS的基本使用 环境: Windows 8.1 64bit英文版,Visua ...

  2. ATS项目更新(3) 远程同步到执行机器

    1: echo %time% 2: 3: 4: rem ** ipc and mapping 5: c: 6: net use x: /del 7: net use y: /del 8: net us ...

  3. Symfony——如何使用Assetic实现资源管理

    1. 安装和启用 从Symfony 2.8开始,Assetic不再包含在Symfony Standard Edition中.在使用其任何功能之前,请在您的项目中安装执行此控制台命令的 AsseticB ...

  4. springboot 上传图片

    1. 创建多层目录 创建多层目录要使用File的mkdirs()方法,其他可以使用mkdir()方法. 2. 文件大小限制 配置文件中,在spring1.4以后要使用 ` spring.http.mu ...

  5. Ubuntu更改 resolv.conf 重启失效

    更改Ubuntu的 resolv.conf的时候,重启的时候,经常又给重置了.google大法找到方法. sudo apt-get install resolvconf  原来Ubuntu的resol ...

  6. XML序例化工具类

    Model: [XmlRoot(ElementName = "root")] public class BookModel { [XmlElement] public string ...

  7. 如何将编码转为自己想要的编码 -- gbk utf-8

    /**  * 数组转码  * @param array $arr 要转码的数组  * @param string $in_charset 输入的字符集  * @param string $out_ch ...

  8. Delphi中close与Terminate方法的区别

    在有多个Form窗体时可以体现出来.用close是只关闭本窗体,而用Application.terminate是关闭整个程序,包括所有窗体.(1)当Close是一个主窗体时,程序会退出.Close会发 ...

  9. git服务器创建,冲突解决,远程仓库获取指定文件

    1.git服务器创建 在公司多人协作开发的情况下,不能简单地使用github,因为github是互联网公开的,这种情况公司的代码的保密性就会丧失了.这种情况下,需要创建git服务器. 登录服务器,使用 ...

  10. 在UWP 将BitmapImage转换为 WriteableBitmap

    原文: How to convert BitmapImage to WriteableBitmap in Universal application for windows 10? 您可以直接从文件将 ...