相关疑难解决方法(0)

<context:annotation-config>与<context:component-scan>之间的区别

我正在学习春天3,我似乎没有把握背后的功能<context:annotation-config><context:component-scan>.

根据我的阅读,他们似乎处理不同的注释(@ Required,@ Autowired etc vs @Component,@ Repository,@ Service等),但也从我读过的内容中注册了相同的bean后处理器类.

为了让我更加困惑,有一个@Required属性@Autowired.

有人可以对这些标签有所了解吗?什么是相似的,什么是不同的,一个被另一个取代,它们相互完成,我需要其中一个,两者都有吗?

java configuration spring annotations spring-3

672
推荐指数
10
解决办法
32万
查看次数

servlet中的<mvc:annotation-driven />和<context:annotation-config />有什么区别?

我正在从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配置文件?

spring spring-mvc spring-3

154
推荐指数
3
解决办法
14万
查看次数

为什么Spring MVC用404响应并报告"在DispatcherServlet中找不到带有URI [...]的HTTP请求的映射"?

我正在编写一个部署在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)

最后,我有一个@Controllercom.example.controllers

@Controller
public class ExampleController {
    @RequestMapping(path = "/home", …
Run Code Online (Sandbox Code Playgroud)

java spring servlets spring-mvc

82
推荐指数
2
解决办法
5万
查看次数

Spring mvc controller bean configuration

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)

java spring spring-mvc

3
推荐指数
1
解决办法
4万
查看次数