Java 弹簧靴筒';在添加另一个SpringMVC项目作为依赖项之后,找不到合适的URL映射
我正在从事一个SpringBoot项目,该项目从另一个SpringMVC项目获取服务。在我添加服务项目之前,URL映射对于spring启动项目非常有效。但是在添加SpringMVC项目作为依赖项并扫描所有组件和映射程序之后,该项目无法确定URL映射。(两个项目没有任何编译错误) 这是我的spring boot项目控制器Java 弹簧靴筒';在添加另一个SpringMVC项目作为依赖项之后,找不到合适的URL映射,java,spring,spring-boot,Java,Spring,Spring Boot,我正在从事一个SpringBoot项目,该项目从另一个SpringMVC项目获取服务。在我添加服务项目之前,URL映射对于spring启动项目非常有效。但是在添加SpringMVC项目作为依赖项并扫描所有组件和映射程序之后,该项目无法确定URL映射。(两个项目没有任何编译错误) 这是我的spring boot项目控制器 @Controller public class PriceFactorController { private static final Logger logger
@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;
}
}
另外,
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);
}
}
这就是我添加的依赖项
<dependency>
<groupId>com.xxc</groupId>
<artifactId>price-engine</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
com.xxc
价格引擎
0.0.1-快照
您的@RequestMapping
@RestController
@RequestMapping("/api/v1/price-factor")
public class PriceFactorController{
.......
}
您的
@RequestMapping
@RestController
@RequestMapping("/api/v1/price-factor")
public class PriceFactorController{
.......
}
您必须为这两个项目添加基本包
@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.xxc
和lk.xcc
中的组件。您必须为这两个项目添加基本包
@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.xxc
和lk.xcc
中的组件。您是如何将另一个项目添加为依赖项的?我刚刚将、、作为依赖项添加到pom.xml中。我在springBoot项目的主类上方添加了以下行。@MapperScan(“com.xxc”)@ComponentScan(basePackages={“com.xxc”})@SpringBootApplication(exclude={SecurityAutoConfiguration.class})您的两个项目是否具有相同的组id?不,这些组id是不同的。Spring boot as lk.xxc和Spring mvc项目将com.xxcAdd您的主类和两个项目的groupId添加到问题中,您是如何将另一个项目添加为依赖项的?我刚刚将、、添加到pom.xml中作为依赖项。我在springBoot项目的主类上方添加了以下行。@MapperScan(“com.xxc”)@ComponentScan(basePackages={“com.xxc”})@SpringBootApplication(exclude={SecurityAutoConfiguration.class})您的两个项目是否具有相同的组id?不,这些组id是不同的。Spring boot作为lk.xxc和Spring mvc项目将com.xxc与您的主类和这两个项目的groupId联系起来,我将这个@GetMapping(“/price”)用于controller中的映射。这不对吗?这不是完全取决于您的设计的rest服务。这只是我的建议。当您在两个不同的类中有两个相同的'@GetMapping(“/price”)'时。你会得到问题,事实上,这种情况不仅发生在价格上。当我放置正确的url时,我将@GetMapping(“/price”)放在控制器中的映射中。这不对吗?这不是完全取决于您的设计的rest服务。这只是我的建议。当您在两个不同的类中有两个相同的'@GetMapping(“/price”)'时。你会得到问题,事实上,这种情况不仅发生在价格上。当我输入正确的url时,它就会发生。