Per Spring 3 document, The IoC container, the @Named
annotation is a standard equivalent to the @Component
annotation.
Since @Repository
, @Service
, and @Controller
are all @Component
, I tried to used @Named
for all of them in my Spring MVC application. It works fine. But I found the replacement of @Controller
seems to have a bug. In the controller class, originally, it was
@Controller
public class MyController{
...
}
It works fine. When I changed @Controller
to @Named
@Named
public class MyController{
...
}
It failed with error:
"No mapping found for HTTP request with URI ...".
But if I added @RequestMapping
to the class as follow
@Named
@RequestMapping
public class MyController{
...
}
It would work as expected.
For @Repository
and @Service
, I can simply replace them with @Named
with no issue. But the replacement of @Controller
needs extra work. Is there anything I am missing in the configuration?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…