を実行している問題は、私が初めての両方春ブーツとMavenのを使用している、と私は何をする必要があるかについて、いくつかの修正を加えて、This tutorialを追っています。私は「REST APIの構築」セクションを終了しました。アプリケーションを実行して、これまでの作業が実際に動作することを確認します。私は、コマンドを実行してくださいMavenの春ブーツ:REST APIの
mvn spring-boot:run -e >> output.txt
ビルドが失敗し、私はthe following outputを取得し、私にとってはちんぷんかんぷん約500行です。これを読んで、私は何がうまくいかないのか分かりません。
Pet.Java
package com.Me;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.HashSet;
import java.util.Set;
@Entity
public class Pet {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getPhoto() {
return photo;
}
public String getStatus() {
return status;
}
@JsonIgnore
public String name;
public String photo;
public String status;
public Pet(String name, String photo, String status) {
this.name = name;
this.photo = photo;
this.status = status;
}
Pet() {
}
}
PetRepo.Java
package com.Me;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
public interface PetRepo extends JpaRepository<Pet, Long> {
Optional<Pet> findByName(String name);
Optional<Pet> findByStatus (String status);
}
PetstoreApplication.Java
package com.Me;
import java.util.Arrays;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class PetstoreApplication {
@Bean
CommandLineRunner init(PetRepo petRepo) {
return (evt) -> Arrays.asList(
"jhoeller,dsyer,pwebb,ogierke,rwinch,mfisher,mpollack,jlong".split(","))
.forEach(
a -> {
Pet pet = petRepo.save(new Pet(a, "meh", "Meh"));
});
}
public static void main(String[] args) {
SpringApplication.run(PetstoreApplication.class, args);
}
}
@RestController
@RequestMapping("/{userId}/bookmarks")
class PetRestController {
private final PetRepo petRepo;
@RequestMapping(value="/{petId}", method = RequestMethod.GET)
Pet getPet(@PathVariable Long petId) {
return this.petRepo.findOne(petId);
}
@Autowired
PetRestController(PetRepo petRepo){
this.petRepo = petRepo;
}
}
のpom.xml
<?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>com.Me</groupId>
<artifactId>petstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>petstore</name>
<description>Petstore Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
私は本当に何が起こっているのか分かりませんし、この問題を手にしていただければ幸いです。
これは役に立ちます。このレポと比較して、欠落しているものを確認してください。 https://github.com/joshlong/bookmarks/tree/tutorial/model/ – Gangaraju