我在CourseApiApp.java文件中有以下代码:
package io.myapp.hellospringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
当我按下播放按钮时,我看到以下控制台消息:
main] i.a.hellospringboot.CourseApiApp : Starting CourseApiApp on johndoe-MacBook-Pro.local with PID 22730 (/Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot/target/classes started by john doe in /Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot)
2017-05-02 21:28:29.454 INFO 22730 --- [ main] i.a.hellospringboot.CourseApiApp : No active profile set, falling back to default profiles: default
2017-05-02 21:28:29.552 INFO 22730 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.838 INFO 22730 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-05-02 21:28:30.917 INFO 22730 --- [ main] i.a.hellospringboot.CourseApiApp : Started CourseApiApp in 2.122 seconds (JVM running for 2.614)
2017-05-02 21:28:30.919 INFO 22730 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.920 INFO 22730 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
更新:这是POM.xml文件:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
我的GreetingController.java文件:
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
@RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
}
答案 0 :(得分:6)
根本原因是maven缓存中的一个损坏的jar。删除~/.m2/repository
解决了这个问题。
另一种选择是运行mvn dependency:purge-local-repository
答案 1 :(得分:3)
请删除.m2 repository
中的文件
主要从以下位置删除文件:
C:\Users\{UserName}\.m2\repository\org\apache
再次通过更新POM文件来构建应用程序,问题得到解决。
答案 2 :(得分:0)
您必须向文件pom.xml添加依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
答案 3 :(得分:0)
由于jar文件损坏,我遇到了同样的问题,因此我决定使用最新的spring boot依赖项,并且它的工作原理很好。您只需要更新POM文件并重新构建即可。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.javabrains.springbootquickstart</groupId>
<artifactId>course.api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springbootapi</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
答案 4 :(得分:0)
这差点让我发疯。好吧,请看上面@PhilWebb的评论:
这意味着您的类路径错误(没有Tomcat),或者您有一个 属性集会禁用网络支持。
我不得不回到我的Application类,发现我正在这样做:
producer = KafkaProducer(
bootstrap_servers=get_kafka_brokers(),
security_protocol='SSL',
ssl_context=get_kafka_ssl_context(),
value_serializer=lambda v: json.dumps(v).encode('utf-8'),
batch_size=0,
acks=1
)
message = {}
producer.send(app.config['NEW_LOG_TOPIC'], message, key=str(device.id).encode('utf-8'))
我已将while (timer < timeout) {
if(in.available() > 0) {
byte[] buf = new byte[in.available()];
in.read(buf);
if(ByteBuffer.wrap(buf).getDouble() == token) {
System.out.println("ALIVE");
return context.transformMessageToString();
}
System.out.println("Token not matched");
}
timer = System.currentTimeMillis()-start;
}
System.out.println("NOT ALIVE");
throw e;//timeout try reconect
设置为 public static void main(String[] args) {
new SpringApplicationBuilder(OasisEstoreManagerApiApplication.class)
.web(WebApplicationType.NONE)
.run(args);
}
我将其更改为WebApplicationType
并且有效。
这是在我尝试了所有操作之后,包括删除NONE
目录。
希望这对某人有帮助。