添加数据库和安全功能后,@ RequestMapping停止工作

时间:2017-03-25 10:38:33

标签: java spring spring-boot mapping

我正在使用Spring Boot编写小型Web应用程序。一切都工作得很好,然后我添加了一些hibernate和Spring Security功能,现在我的@RequestMapping不起作用。现在我只得到一些关于这样的映射的日志:

  

o.s.w.s.handler.SimpleUrlHandlerMapping:将URL路径[/**/favicon.ico]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

类型的处理程序上      

swsmmaRequestMappingHandlerMapping:Mapped" {[/ error],methods = [],params = [],headers = [],consume = [],produce = [],custom = []}&#34 ; on public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

     

swsmmaRequestMappingHandlerMapping:Mapped" {[/ error],methods = [],params = [],headers = [],consume = [],produce = [text / html],custom = []} " on public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)

     

o.s.w.s.handler.SimpleUrlHandlerMapping:将URL路径[/ webjars / *]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上   2017-03-25 11:30:34.516 INFO 4644 --- [main] oswshandler.SimpleUrlHandlerMapping:将URL路径[/ **]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上/ p>

我的控制器看起来像:

@Controller
@RequestMapping("/")
public class HomeController {

    @RequestMapping(method=RequestMethod.GET)
    public String home(Model model){
        String welcome = new String("test");
        model.addAttribute("welcome", welcome);
        return "home";
    }
}

Application.java

@Configuration      
@EnableAutoConfiguration
@EnableTransactionManagement
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

这是我的项目结构:

structure

2 个答案:

答案 0 :(得分:0)

问题解决了。我的验证器类缺少@Component注释。

答案 1 :(得分:0)

将以下注释添加到Application类中:

// this will fix your problem (remember that by default without package declare it will look in package where Application is)
@ComponentScan("your_package_name")

// it does not require comment :)
@EnableJpaRepositories("your_package_name") 
@EntityScan("your_package_name")