我正在学习春天3,我似乎没有把握背后的功能<context:annotation-config>和<context:component-scan>.
根据我的阅读,他们似乎处理不同的注释(@ Required,@ Autowired etc vs @Component,@ Repository,@ Service等),但也从我读过的内容中注册了相同的bean后处理器类.
为了让我更加困惑,有一个@Required属性@Autowired.
有人可以对这些标签有所了解吗?什么是相似的,什么是不同的,一个被另一个取代,它们相互完成,我需要其中一个,两者都有吗?
我正在从Spring 2.5迁移到Spring 3.
他们介绍了<mvc:annotation-driven />哪些黑魔法.这应该只在servlet配置文件中声明.
在Spring 2.5中,我刚刚使用<context:annotation-config />和<context:component-scan base='...'/>标记声明application-context.xml和调度程序servlet配置XML以及适当的基础包进行扫描.
所以,我不知道是什么样的区别mvc:annotation-driven,并context:annotation-config在servlet配置标签和我有什么可以消除在春季3配置文件?
我正在编写一个部署在Tomcat上的Spring MVC应用程序.请参阅以下最小,完整且可验证的示例
public class Application extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { };
}
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { SpringServletConfig.class };
}
protected String[] getServletMappings() {
return new String[] { "/*" };
}
}
Run Code Online (Sandbox Code Playgroud)
哪里SpringServletConfig是
@Configuration
@ComponentScan("com.example.controllers")
@EnableWebMvc
public class SpringServletConfig {
@Bean
public InternalResourceViewResolver resolver() {
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setPrefix("/WEB-INF/jsps/");
vr.setSuffix(".jsp");
return vr;
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我有一个@Controller包com.example.controllers
@Controller
public class ExampleController {
@RequestMapping(path = "/home", …Run Code Online (Sandbox Code Playgroud) I am working on a project using Spring mvc and I counter a problem that a handler is auto generated when I start the server.
Here is the code:
Controller
@Controller
@RequestMapping(value="userstory/{projectid}/{sprintid}/")
@SessionAttributes(value = "user")
public class UserstoryController {
private ISprintService sprintService;
private IUserStoryService userStoryService;
private IProjectService projectService;
private IBurnDownChartService burnDownChartService;
private ITaskService taskService;
public void setSprintService(ISprintService sprintService) {
this.sprintService = sprintService;
}
public void setUserStoryService(IUserStoryService userStoryService) {
this.userStoryService = userStoryService;
}
public void setProjectService(IProjectService projectService) {
this.projectService = projectService; …Run Code Online (Sandbox Code Playgroud)