Spring Boot 应用程序不会熬夜

Vat*_*son 6 rest spring spring-boot

我创建了一个简单的 REST Spring 启动应用程序。我看到它开始,但它立即关闭。日志中没有错误。

下面是代码和日志。

代码:

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

    }

} 
Run Code Online (Sandbox Code Playgroud)

日志:


    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

小智 7

如果您使用的是 maven,请查看您的 pom.xml 文件,然后您会发现如下内容:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

它应该改为:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)