Ren*_*ndy 7 java spring spring-mvc
如果我在spring工具包中创建一个标准的Spring项目,那就太棒了!
我访问localhost:8080 /问候并得到我的hello world响应.
如果我将这2个文件复制到我的源代码树中的另一个包中,然后访问localhost:8080/greeting我得到一个:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Oct 17 18:15:45 BST 2014
There was an unexpected error (type=Not Found, status=404).
Run Code Online (Sandbox Code Playgroud)
将3个类移动到相同的默认包中可以解决问题,但是从源树组织的角度来看,这不是我想要做的.
我希望这是由于一些自动配置所以请有人告诉我我必须做什么才能让我的项目支持多个包作为控制器和对象.
pon*_*ndr 15
如果您的代码在本教程中看起来像,那么打开servlet-context.xml
并更改
<context:component-scan base-package="..."/>
Run Code Online (Sandbox Code Playgroud)
您可以列出多个包.使用逗号作为分隔符.
更新:
那是基于XML的配置.
如果您创建"Spring Boot App",则配置是基于注释的.在这种情况下,您需要搜索带注释的类@ComponentScan
.通常,它是一个名为AppConfig的主类或类.
默认情况下,它从类的包开始递归搜索控制器和其他组件.您可以向此注释添加参数,如下所示:
@ComponentScan({ "x.y.z.services", "x.y.z.controllers" })
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8410 次 |
最近记录: |