简体   繁体   中英

Maven Spring Boot application stuck

I have created a sample Spring Boot application which i can Run with Run as Spring Boot App option in STS. I can also run Junit tests with Run as Junit Option without any issue.

But when i try to package my application with Maven using Run as Maven Build option, application just stuck at some point always.

I have below piece of code at starting level.

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();

My console looks like stuck here

    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)

I am only expecting two values from Scan . where i Have given many values to just show the application stuck at this point.

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**

UPDATE: When i ran mvn spring-boot:run , It works fine. But If i ran using mvn clean install spring-boot:run , it stuck in the middle Any Help?

The application is stuck because it is waiting for input data in scan.next() method call.

As per Java documentation :

This method may block while waiting for input to scan, even if a previous invocation of hasNext() returned true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM