我是Spring Framework的新手。我正在学习一个教程。它位于https://spring.io/guides/gs/rest-service/
下面是我的行为 STS的版本是3.7.2复制并粘贴来源
改变“包你好;” to“package com.example;”
package com.example;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
package com.example;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RestServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RestServiceApplication.class, args);
}
}
我点击[Run As] - [Spring Boot App],但很奇怪。如果我下载并运行该项目,那就很好了。如果我创建项目并键入源,则会发生错误。我认为build.gradle有问题。但我不确切知道。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.0.RELEASE)
2015-12-02 15:51:50.706 INFO 4808 --- [ main] com.example.RestServiceApplication : Starting RestServiceApplication on John-PC with PID 4808 (C:\Users\John\Documents\workspace-sts-3.7.1.RELEASE\rest-service\bin started by John in C:\Users\John\Documents\workspace-sts-3.7.1.RELEASE\rest-service)
2015-12-02 15:51:50.708 INFO 4808 --- [ main] com.example.RestServiceApplication : No profiles are active
2015-12-02 15:51:50.744 INFO 4808 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@45afc369: startup date [Wed Dec 02 15:51:50 KST 2015]; root of context hierarchy
2015-12-02 15:51:51.334 INFO 4808 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-12-02 15:51:51.343 INFO 4808 --- [ main] com.example.RestServiceApplication : Started RestServiceApplication in 0.818 seconds (JVM running for 1.268)
2015-12-02 15:51:51.343 INFO 4808 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@45afc369: startup date [Wed Dec 02 15:51:50 KST 2015]; root of context hierarchy
2015-12-02 15:51:51.345 INFO 4808 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
我该如何解决?