私はスプリングブートプロジェクトを実行しようとしています。リリース1.5.2を選択している間は、requestMappingのURLは機能しません。それは私に404エラーを常に与える。@RequestMapping Springバージョン1.5.2で動作しません。リリース
タグがないか、バージョンの設定が変更された場合は、誰かにご確認ください。または私が見逃した他のどんな細かいものでもありません。
の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.prizy</groupId>
<artifactId>ProductApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ProductApi</name>
<description>Project for Product Managment</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
コントローラー:
package com.prizy.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import com.prizy.model.Product;
import com.prizy.service.ProductService;
@RestController
public class ProductController {
@Autowired
private ProductService productService;
@RequestMapping("/products")
public List<Product> getAllProducts() {
return productService.getAllProducts();
}
@RequestMapping("/hi")
public String getString() {
return "Hi";
}
@RequestMapping("/products/{productId}")
public Product getProduct(@PathVariable int productId){
return productService.getTopic(productId);
}
@RequestMapping(method=RequestMethod.POST, value="/products")
public void addProduct(@RequestBody Product product) {
productService.addProduct(product);
}
@RequestMapping(method=RequestMethod.PUT, value="/products/{productId}")
public void updateProduct(@RequestBody Product product, @PathVariable int productId) {
productService.updateProduct(product,productId);
}
@RequestMapping(method=RequestMethod.DELETE, value="/products/{productId}")
public void deleteProduct(@PathVariable int productId) {
productService.deleteProduct(productId);
}
}
メイン・クラスが
package com.prizy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableAutoConfiguration
@SpringBootApplication
public class ProductApiApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApiApplication.class, args);
}
}
です。注:質問UPD詳細はatedを参照してください。
アクセスしようとしているURLは何ですか? – developer
http:// localhost:8080/hi – Ashu
'package com.prizy.controller':メインクラスはどこですか? – chrylis