首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring boot在添加另一个spring MVC项目作为依赖项后无法找到适当的URL映射

Spring boot在添加另一个spring MVC项目作为依赖项后无法找到适当的URL映射
EN

Stack Overflow用户
提问于 2018-05-28 18:26:25
回答 2查看 1.1K关注 0票数 0

我正在做一个spring boot项目,它接受了另一个spring mvc项目的服务。在我添加服务项目之前,URL映射非常适合spring boot项目。但是在将spring MVC项目添加为依赖项并扫描所有组件和映射器之后,该项目无法确定URL映射。(两个项目没有任何编译错误)

这是我的spring boot项目的控制器。

代码语言:javascript
复制
@Controller
public class PriceFactorController {

    private static final Logger logger = LoggerFactory.getLogger(PriceFactorController.class);


/*

  @Autowired
    PriceAggregator2 priceAggregator2;
*/

    @GetMapping("/price")
    public ModelAndView priceGet() {
        ModelAndView modelAndView = new ModelAndView();
        PriceSearch priceSearch = new PriceSearch();
        modelAndView.addObject("priceSearch", priceSearch);
        modelAndView.setViewName("price");
        return modelAndView;
    }

    @PostMapping("/price")
    public ModelAndView pricePost(
            @Valid @ModelAttribute("priceSearch") PriceSearch priceSearch,
            BindingResult bindingResult,
            Model model) {

        priceSearch.makeDestinationList();
        priceSearch.makeTravellerList();

        //  List<PricingResult> resultSet=priceAggregator2.getPriceResultList(priceSearch.getPriceSearchDTO());

        ModelAndView modelAndView = new ModelAndView();
        logger.debug(priceSearch.toString());
        if (bindingResult.hasErrors()) {
            modelAndView.setViewName("price");
        } else {
            modelAndView.setViewName("redirect:/result");
        }
        return modelAndView;
    }


    @GetMapping("/result")
    public ModelAndView priceResult(
            @RequestParam(value = "key", required = false) String key,
            Model model) {
        Result result = new Result();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("result", result);
        modelAndView.setViewName("result");
        return modelAndView;
    }
}

但它似乎没有寻找这个控制器,这是我的日志。

代码语言:javascript
复制
2018-05-28 16:42:15.114 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/price]
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /price
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/price]
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/price] are [/**]
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/price] are {}
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/price] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@45cc601]]] and 1 interceptor
2018-05-28 16:42:15.115 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/price] is: -1
2018-05-28 16:42:15.116 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-05-28 16:42:15.116 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-05-28 16:42:15.116 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2018-05-28 16:42:15.116 DEBUG 27866 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-05-28 16:42:15.117 DEBUG 27866 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]
2018-05-28 16:42:15.117 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/error] is: -1
2018-05-28 16:42:15.131 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html])
2018-05-28 16:42:15.134 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.view.freemarker.FreeMarkerView   : No FreeMarker view found for URL: error.ftl
2018-05-28 16:42:15.134 DEBUG 27866 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@7be99ccd] based on requested media type 'text/html'
2018-05-28 16:42:15.134 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@7be99ccd] in DispatcherServlet with name 'dispatcherServlet'
2018-05-28 16:42:15.134 DEBUG 27866 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Successfully completed request

另外,

代码语言:javascript
复制
package lk.xxc;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

//http://www.thymeleaf.org/doc/articles/layouts.html'
@MapperScan("com.xxc")
@ComponentScan(basePackages = {"com.xxc"})
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
public class SpringBootWebApplication {

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

}

这是我添加的依赖项

代码语言:javascript
复制
   <dependency>
            <groupId>com.xxc</groupId>
            <artifactId>price-engine</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-28 18:53:19

您必须为这两个项目添加基包。

代码语言:javascript
复制
@ComponentScan(basePackages = {"com.xxc", "lk.xcc"})
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
public class SpringBootWebApplication {

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

这将扫描com.xxclk.xcc中的组件

票数 2
EN

Stack Overflow用户

发布于 2018-05-28 18:31:30

你的@RequestMapping在哪里

代码语言:javascript
复制
@RestController
@RequestMapping("/api/v1/price-factor")
public class PriceFactorController{
.......
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50564252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档