Java 私有JVM上的Spring boot ware部署,无法命中控制器
我使用spring boot构建了一个后端应用程序,我在mochahost中购买了一个带有私有JVM的主机,在部署war文件后,我无法访问映射的控制器 在mochahost中,当部署WAR时(使用deploy WAR选项),WAR文件上载到位置Java 私有JVM上的Spring boot ware部署,无法命中控制器,java,maven,spring-mvc,tomcat,spring-boot,Java,Maven,Spring Mvc,Tomcat,Spring Boot,我使用spring boot构建了一个后端应用程序,我在mochahost中购买了一个带有私有JVM的主机,在部署war文件后,我无法访问映射的控制器 在mochahost中,当部署WAR时(使用deploy WAR选项),WAR文件上载到位置“/jvm/apache-tomcat-8.0.20/domains/[mydomain]/”,然后我运行tomcat并在同一位置提取webapp,webapp是我的WAR文件名 我的主要班级: @SpringBootApplication public
“/jvm/apache-tomcat-8.0.20/domains/[mydomain]/”
,然后我运行tomcat并在同一位置提取webapp,webapp是我的WAR文件名
我的主要班级:
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
我还创建了一个servlet初始化类
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainApplication.class);
}
}
我试图击中的控制器是:
@RestController
@RequestMapping("/products")
public class ProductsController {
@Autowired
private ProductService productService;
@Autowired
ServletContext servletContext;
@RequestMapping(method=RequestMethod.GET)
public ResponseEntity<List<Product>> getAllProducts(){
return new ResponseEntity<List<Product>>(productService.getAllProducts(), HttpStatus.OK);
}
@RestController
@请求映射(“/products”)
公共类产品控制器{
@自动连线
私人产品服务;
@自动连线
ServletContext ServletContext;
@RequestMapping(method=RequestMethod.GET)
公共响应getAllProducts(){
返回新的ResponseEntity(productService.getAllProducts(),HttpStatus.OK);
}
我试图访问htttp://[mydomain]/webapp/products的url,但我没有找到
404页面
,非常感谢您的帮助我解决了这个问题,问题是servlet初始值设定项不是主应用程序类,我将它们设置为一个类,问题就消失了
@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainApplication.class);
}
}
你试过htttp://[mydomain]/产品吗?是的,我试过,但效果不好