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
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With