[英]How to run spring boot maven project on local tomcat
This is basically my first Spring boot project and im trying to run it on my local tomcat.这基本上是我的第一个 Spring 启动项目,我试图在我的本地 tomcat 上运行它。 So that I can use Postman for GET requests using RESTful api.这样我就可以将 Postman 用于使用 RESTful api 的 GET 请求。
@RestController
@RequestMapping(value = "/shop")
public class ShopController {
@Autowired
ShopService shopService;
@GetMapping(value = "/{id}")
public @ResponseBody Shop getTestData(@PathVariable String id) {
return shopService.getShopBasedOnId(id);
}
}
Basically what I'd want to do is run an sh script or intellij configuration to build my maven project and deploy it to my localhost:8080基本上我想要做的是运行一个 sh 脚本或 intellij 配置来构建我的 maven 项目并将其部署到我的 localhost:8080
The above comments are correct if you have a local instance of Tomcat running.如果您有 Tomcat 的本地实例正在运行,则上述注释是正确的。 If you're looking to test, simply run:如果您要测试,只需运行:
mvn spring-boot:run
If you're using the Spring parent pom for dependencies, the plugin is configured.如果您使用 Spring 父 pom 作为依赖项,则已配置插件。 You'll need a Main function.您需要一个主 function。 Mine typically looks like:我的通常看起来像:
@SpringBootApplication
@NoArgsConstructor @ToString @Log4j2
public class Launcher extends SpringBootServletInitializer {
public static void main(String[] argv) throws Exception {
SpringApplication application = new SpringApplication(Launcher.class);
application.run(argv);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder appli\
cation) {
return application.sources(Launcher.class);
}
}
You don't have to run it in external tomcat to test using postman.您不必在外部 tomcat 中运行它即可使用 postman 进行测试。 You can use boot dash board in spring sts or equivalent in intellij.您可以在 spring sts 或 intellij 中的等效项中使用引导仪表板。 If you still want to use external tomcat, then you need to package as war instead of embedded jar.如果你还想使用外置tomcat,那么你需要package作为war而不是嵌入式jar。 Look at his article for converting jar to war boot war deploy查看他的文章,将 jar 转换为战启动战部署
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.