Maven Spring Boot应用程序卡住了

时间:2018-03-10 19:18:29

标签: java spring maven spring-boot

我已经创建了一个示例Spring Boot应用程序,我可以在STS中运行Run as Spring Boot App选项。我也可以使用Run as Junit Option运行Junit测试,没有任何问题。

但是当我尝试使用Run as Maven Build选项将我的应用程序与Maven打包时,应用程序总是停留在某个点上。

我在起始级别下面有一段代码。

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
    Scanner scan = new Scanner(System.in);

    String name = scan.next();// It just stuck here especially when i use run as maven build

    Double balance = scan.nextDouble();
    Card card = new Card(name, balance);

    scan.close();

我的控制台看起来像是在这里

    2018-03-11 00:39:58.619  INFO 22835 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : Starting JourneyDAOImplTest on localhost.localdomain with PID 22835 (started by root in /root/Documents/workspace-sts-3.9.0.RELEASE/oystercard)
2018-03-11 00:39:58.629  INFO 22835 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : No active profile set, falling back to default profiles: default
2018-03-11 00:39:58.931  INFO 22835 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@6c1a5b54: startup date [Sun Mar 11 00:39:58 IST 2018]; root of context hierarchy
2018-03-11 00:40:04.630  INFO 22835 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@6c1a5b54: startup date [Sun Mar 11 00:39:58 IST 2018]; root of context hierarchy
2018-03-11 00:40:04.991  INFO 22835 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-11 00:40:04.995  INFO 22835 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-11 00:40:05.155  INFO 22835 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 00:40:05.177  INFO 22835 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 00:40:05.427  INFO 22835 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 00:40:05.942  INFO 22835 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : Started JourneyDAOImplTest in 8.48 seconds (JVM running for 12.679)

我只期待来自Scan的两个值。我已经给出了许多值,只是显示应用程序在这一点上停留。

2018-03-11 08:00:50.876  INFO 18520 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : Starting JourneyDAOImplTest on localhost.localdomain with PID 18520 (started by root in /root/Documents/workspace-sts-3.9.0.RELEASE/oystercard)
2018-03-11 08:00:50.880  INFO 18520 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : No active profile set, falling back to default profiles: default
2018-03-11 08:00:51.105  INFO 18520 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@6c1a5b54: startup date [Sun Mar 11 08:00:51 IST 2018]; root of context hierarchy
2018-03-11 08:00:59.383  INFO 18520 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@6c1a5b54: startup date [Sun Mar 11 08:00:51 IST 2018]; root of context hierarchy
2018-03-11 08:00:59.739  INFO 18520 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-11 08:00:59.742  INFO 18520 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-11 08:00:59.880  INFO 18520 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 08:00:59.881  INFO 18520 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 08:01:00.053  INFO 18520 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-11 08:01:02.014  INFO 18520 --- [           main] c.a.o.t.daoImpl.test.JourneyDAOImplTest  : Started JourneyDAOImplTest in 12.566 seconds (JVM running for 18.154)

**Rajesh
30.0
30.0
Rajesh
Rajesh
30.0
fdsfdsfdsjfds
46548768672**

更新: 当我运行mvn spring-boot:run时,它运行正常。 但如果我使用mvn clean install spring-boot:run运行,它会卡在中间 任何帮助?

1 个答案:

答案 0 :(得分:1)

应用程序被卡住了,因为它正在等待scan.next()方法调用中的输入数据。

根据Java documentation

  

即使之前的hasNext()调用返回true,此方法也可能在等待输入扫描时阻塞。