同名不同包?no way

栏目: Java · 发布时间: 5年前

内容简介:spring boot中,两个类,如果名字相同,但位于不同的包,不行的,运行会报错。这真是咄咄怪事。怎么会这样子?生活也是如此,本来以为已经百尺竿头更进一步了,没想到前面是万丈深渊。怎么办?

spring boot中,两个类,如果名字相同,但位于不同的包,不行的,运行会报错。

这真是咄咄怪事。怎么会这样子?生活也是如此,本来以为已经百尺竿头更进一步了,没想到前面是万丈深渊。

怎么办?

加注解咯。俺家spring boot,最喜欢注解了!

//控制器1
package com.ibm.lanbase.modules.res.controller;

@Controller("resIndexController")//注解,相当于别名?
@RequestMapping(value = "/slider/res")
public class IndexController {

}

//控制器2
package com.ibm.lanbase.modules.tj.controller;

@Controller("tjIndexController")
@RequestMapping(value = "/slider/tj")
public class IndexController {

}

附录2.声明Bean的注解

如何吸引Spring容器的注意而“有幸”成为Spring 容器管理的Bean呢?

在Spring Boot中就依靠注解,Spring提供了多个注解来声明Bean为Spring容器管理的Bean,注解不同代表的含义不同,但是对Spring容器来说都是Spring管理的Bean

声明Bean的注解有:

@Component 没有明确角色的组件

@Service 在业务逻辑层(Service层)使用

@Repositpry 在数据访问层(dao层)使用

@Controller 用于标注控制层组件

@RestController

大概,这些bean,后面都可以带上注解的吧?


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Shallows

The Shallows

Nicholas Carr / W. W. Norton & Company / 2010-6-15 / USD 26.95

"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码