当我运行spring boot项目的命令时:
mvn spring-boot:run
代码显示生成成功消息,并结束。
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.084 s
[INFO] Finished at: 2019-06-03T11:28:11+05:30
[INFO] Final Memory: 64M/899M
[INFO] ------------------------------------------------------------------------
但是我想在http://localhost:8080的浏览器上显示工作代码。 应用程序立即停止而不是启动Web服务器,该项目结束。 代码是否需要进行任何更改才能在localhost上运行?
这是我的OMSApplication.java类
@EnableScheduling
@SpringBootApplication(exclude=DataSourceAutoConfiguration.class)
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
@EnableEnvironmentJKS
public class OMSApplication extends SpringBootServletInitializer{
private static final Logger log = LoggerFactory
.getLogger(OMSApplication.class);
public static void main(String[] args) {
ApplicationContext applicationContext = SpringApplication.run(
OMSApplication.class, args);
log.info(" Application context created: {}" , applicationContext);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(OMSApplication.class);
}
}
这是pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.mpms.services</groupId>
<artifactId>oms-services</artifactId>
<!-- <version>0.0.1-SNAPSHOT</version>-->
<packaging>war</packaging>
<name>oms-services</name>
<description>oms services</description>
<parent>
<groupId>com.example.mpms</groupId>
<artifactId>mpms-oms</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
<configuration>
<skip>true</skip>
<!-- <systemPropertyVariables>
<APIE_PLATFORM>DEV</APIE_PLATFORM>
<APIE_REGION>US</APIE_REGION>
<APIE_ZONE>STL</APIE_ZONE>
</systemPropertyVariables> -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${mvn-site-plugin-version}</version>
</plugin>
</plugins>
</build>
</project>
我没有在这里包括所有依赖项,因为它们很多。
这是控制器类:
@RestController
public class OrderController {
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
@Autowired
private KYCOrderService kycOrderService;
/**
* Health check URL for application via synapse.
*
* */
@GetMapping(value = "/health",produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public ResponseEntity<String> healthCheck() {
String output = String.format("Heartbeat :%s", "Cumulus- Order Management Service: I'm healthy!");
LOGGER.info(output);
return new ResponseEntity<>(output,HttpStatus.OK);
}
@PostMapping(path="/oms/order/kyc", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
@ApiOperation(value = "Place an Offline KYC Order", notes = "Order is placed in central oms", response = OfflineKYCOrderResponse.class, tags={ "OfflineKYCOrderResponse", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OfflineKYCOrderResponse creation OK", response = OfflineKYCOrderResponse.class),
@ApiResponse(code = 201, message = "Created", response = OfflineKYCOrderResponse.class),
@ApiResponse(code = 400, message = "Bad Request", response = OfflineKYCOrderResponse.class),
@ApiResponse(code = 401, message = "Unauthorized", response = OfflineKYCOrderResponse.class),
@ApiResponse(code = 403, message = "Forbidden", response = OfflineKYCOrderResponse.class),
@ApiResponse(code = 404, message = "Not Found", response = OfflineKYCOrderResponse.class)
})
public OfflineKYCOrderResponse placeOfflineKycOrder(@ApiParam(value = "Details of order to be placed" ,required=true)@RequestBody OfflineKYCOrderRequest offlineKYCOrder) {
LOGGER.info("OfflineKYCOrderRequest: {}" , offlineKYCOrder);
OfflineKYCOrderResponse errorResponse = offlineKYCOrder.validateInput();
if (null != errorResponse) {
LOGGER.info("OfflineKYCOrderResponse: {}" , errorResponse);
return errorResponse;
}
ReasonCodes processStatusCode = ReasonCodes.OMS000;
OfflineKYCOrderResponse offlineKYCOrderResponse = new OfflineKYCOrderResponse();
try {
KYCOrder createdKYCOrder = kycOrderService.saveOrder(new KYCOrder(offlineKYCOrder));
offlineKYCOrderResponse.setOrderNumber(createdKYCOrder.getOrder().getOrderId());
} catch (Exception e) {
processStatusCode = ReasonCodes.OMS001;
LOGGER.error("Failed to store order.", e);
} finally {
offlineKYCOrderResponse.setReasonCode(processStatusCode.toString());
offlineKYCOrderResponse.setReasonDescription(processStatusCode.getDescription());
}
LOGGER.info("OfflineKYCOrderResponse: {}" , offlineKYCOrderResponse);
return offlineKYCOrderResponse;
}
}
有人可以帮助解决问题吗?
答案 0 :(得分:0)
您没有在pom.xml中包含spring boot starter软件包, 从pom.xml文件中删除父依赖项,并用以下依赖项替换
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
或者,您可以从目标文件夹使用war并使用tomcat或您选择的任何服务器进行部署。