Spring MVC

1. spring mvc如果return是ok客户端就一直转呀转的,都是拿不到response,如果换成其实字符串就可以,奇怪。

    @RequestMapping(value = "test", produces="application/json;charset=utf-8") 
    @ResponseBody
    public String test(){
        return "ok";
    }

2. @Resource和@Autowired的区别。

比如:

    @Autowired
    private RecommendCommonService recommendService;

这个会去查找RecommendCommonService类型的bean,找不到就报UnsatisfiedDependencyException和NoUniqueBeanDefinitionException错误。

如果是

    @Resource
    private RecommendCommonService recommendService;

就会先去查找有没有id为recommendService的bean,如果没有,就去找有没有类型为RecommendCommonService 的bean.

2017-10-10

对Strping的注入规则有认识上的错误。我今天在一个@Service的类SystemSettingsService的构造函数里,想调用它的一个成员接口

    @Autowired
    private CommonService commonService;

发现,在构造函数调用的时候commonService是空的,但是,把SystemSettingsService放到控制器,或者别的Service类里面作为成员接口的时候,再调用它的一个方法,发现这时候,

commonService不为空。

2018-03-19

如果路径定义(请求接口)重了,会报这个错。

2018-03-19 14:56:14,168 WARN  support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is
java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'gameHallController' method public void com.feikantec.game.suit_tiles.controller.GameHallController.desk(javax.servlet.http.HttpServletResponse,java.lang.Integer,java.lang.Integer) to {[/hallStat]}: There is already 'debugController' bean method public void com.feikantec.game.suit_tiles.controller.DebugController.hallStat(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) mapped.

 

posted on 2017-03-22 17:19  angelshelter  阅读(118)  评论(0编辑  收藏  举报

导航