【发布时间】:2018-10-05 03:24:29
【问题描述】:
尝试从链接编译项目时遇到以下错误:https://howtodoinjava.com/spring/spring-cloud/consul-service-registration-discovery/。我只是运行 spring-cloud-consul-student 没有任何自定义面临以下错误。所有代码如下所示,供参考。
[ERROR] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 项目 spring-cloud-consul-student 上的(默认编译):编译 失败:编译失败: [错误] /C:/Users/pashtikar/Documents/MyELC/spring-cloud-consul-student/src/main/java/com/example/howtodoinjava/SpringCloudConsulStudentApplication.java:[5,50] 包 org.springframework.cloud.client.discovery 不存在 [错误] /C:/Users/pashtikar/Documents/MyELC/spring-cloud-consul-student/src/main/java/com/example/howtodoinjava/SpringCloudConsulStudentApplication.java:[8,2] 找不到标志 [错误] 符号:类 EnableDiscoveryClient [错误] -> [帮助 1] org.apache.maven.lifecycle.LifecycleExecutionException:未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 项目 spring-cloud-consul-student 上的(默认编译):编译 失败 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) 在 org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) 在 org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) 在 org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) 在 org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) 在 org.apache.maven.cli.MavenCli.main (MavenCli.java:194) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke (Method.java:498) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (启动器.java:289) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) 在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) 在 org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) 引起:org.apache.maven.plugin.compiler.CompilationFailureException: 编译失败
SpringCloudConsulStudentApplication
@SpringBootApplication
@EnableDiscoveryClient
public class SpringCloudConsulStudentApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConsulStudentApplication.class, args);
}
}
application.properties
server.port=9098
spring.application.name=student-service
management.security.enabled=false
StudentServiceController
@RestController
public class StudentServiceController {
private static Map<String, List<Student>> schooDB = new HashMap<String, List<Student>>();
static {
schooDB = new HashMap<String, List<Student>>();
List<Student> lst = new ArrayList<Student>();
Student std = new Student("Sajal", "Class IV");
lst.add(std);
std = new Student("Lokesh", "Class V");
lst.add(std);
schooDB.put("abcschool", lst);
lst = new ArrayList<Student>();
std = new Student("Kajal", "Class III");
lst.add(std);
std = new Student("Sukesh", "Class VI");
lst.add(std);
schooDB.put("xyzschool", lst);
}
@RequestMapping(value = "/getStudentDetailsForSchool/{schoolname}", method = RequestMethod.GET)
public List<Student> getStudents(@PathVariable String schoolname) {
System.out.println("Getting Student details for " + schoolname);
List<Student> studentList = schooDB.get(schoolname);
if (studentList == null) {
studentList = new ArrayList<Student>();
Student std = new Student("Not Found", "N/A");
studentList.add(std);
}
return studentList;
}
}
【问题讨论】:
-
你的 pom 在这里比你的代码更重要
标签: java spring-cloud consul