Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot applicaton will not stay up

I created a simple REST Spring boot application. I see it start, but it immediately shutsdown. There is no error in log.

Below is the code and the log.

Code:

@Controller
@ComponentScan
@EnableAutoConfiguration 
@RequestMapping("userInfo")
public class UserUpdateService
{
    private java.util.logging.Logger logger = Logger.getLogger("UserUpdateService");

    @RequestMapping(value="/{userId}", method=RequestMethod.GET, produces = "application/xml; charset=utf-8")
    @ResponseBody
    String getUserInfo(@PathVariable String userId)
    {
        String func = "getUserInfo";
        logger.entering("UserUpdateService", func);

        String retval = "";
        return retval;
    }

    @RequestMapping(value="/{userId}", method=RequestMethod.DELETE, produces = "application/xml; charset=utf-8")
    @ResponseBody
    String removeUser(@PathVariable String userId)
    {
        String retval = "";
        String func = "removeUser";

        logger.entering("UserUpdateService", func);
        return retval;
    }

    @RequestMapping(value="/", method=RequestMethod.PUT, produces = "application/xml; charset=utf-8")
    @ResponseBody
    String addUser(@WebParam (name = "userId")String userId)
    {
        String retval = "";
        String func = "addUser";

        logger.entering("UserUpdateService", func);
        return retval;
    }

    public static void main(String[] args)
    {
        ApplicationContext ctx = SpringApplication.run(UserUpdateService.class, args);

    }

} 

Log:


    Java HotSpot(TM) Server VM warning: .hotspot_compiler file is present but has been ignored.  Run with -XX:CompileCommandFile=.hotspot_compiler to load the file.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.1.RELEASE)

- Starting UserUpdateService on localhost with PID 950 (/opt/home/vatsan/MicroSvcs started by vzwadmin in /opt/home/vatsan/MicroSvcs/bin)
- Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@128edf2: startup date [Thu Jan 29 18:59:37 EST 2015]; root of context hierarchy
- Started UserUpdateService in 0.812 seconds (JVM running for 1.806)
- Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@128edf2: startup date [Thu Jan 29 18:59:37 EST 2015]; root of context hierarchy

like image 332
Vatson Avatar asked Jan 30 '15 00:01

Vatson


People also ask

Can we run Spring Boot application without @SpringBootApplication?

It's not mandatory to put @SpringBootApplication to create a Spring Boot application, you can still use @Configuration and @EnableAutoConfiguration individually as shown in the example given in the next point.

What is @configuration in Spring Boot?

Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.

What is graceful shutdown in Spring Boot?

During a graceful shutdown Spring Boot allows some grace period to the application to finish all the current requests or processes. Once, the grace period is over the unfinished processes or requests are just killed. By default, Spring Boot allows a 30 seconds graceful shutdown timeout.


1 Answers

if you are using maven, check out your pom.xml file, then you will find something like this:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

it should be changed to this instead:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
like image 149
Farzin Avatar answered Nov 15 '22 03:11

Farzin