2017-04-12 5 views
0

私はスプリングブートプロジェクトを実行しようとしています。リリース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); 
    } 
} 

Project Structure

です。注:質問UPD詳細はatedを参照してください。

+0

アクセスしようとしているURLは何ですか? – developer

+0

http:// localhost:8080/hi – Ashu

+0

'package com.prizy.controller':メインクラスはどこですか? – chrylis

答えて

0

。 私はまだ1.5.2リリースで動作していない理由を回答しようとしています。

しかし、このエラーを解決するために、私は私のpom.xmlファイルに変更を下回るこの変更後

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.2.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

をした、私はあまりにもログに要求マッピングのURLを参照することができます:

2017-04-19 11:10:49.785 INFO 4236 --- [   main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.epic.controllers.TestController.sayHello() 
2017-04-19 11:10:49.786 INFO 4236 --- [   main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/helloss]}" onto public java.lang.String com.epic.TestControllerTest.sayHello() 
2017-04-19 11:10:49.789 INFO 4236 --- [   main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 
2 

してください一方、マッピングURLの名前を変更して、質問と同じではないことに注意してください。

1

web.xmlファイルがsrc> main> webapp> WEB-INF> web.xmlで使用可能かどうかを確認します。利用できない場合は、このファイルをcraeteし、以下のコードを使用してください。私は最終的にこのその作業罰金を行った後1.3.2.RELEASE

に春のブートバージョンが変更されたすべてのシナリオをしようとした後

<servlet> 
    <servlet-name>myServlet</servlet-name> 
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:ApplicationContext.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>myServlet</servlet-name> 
    <url-pattern>/api/*</url-pattern> 
</servlet-mapping> 

<filter> 
    <filter-name>encoding-filter</filter-name> 
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <param-name>forceEncoding</param-name> 
     <param-value>true</param-value> 
    </init-param> 
</filter> 

<filter-mapping> 
    <filter-name>encoding-filter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<welcome-file-list> 
    <welcome-file>/index.jsp</welcome-file> 
</welcome-file-list> 
+0

彼は 'web.xml'を持たないSpringブートを使用しています。 –

関連する問題