2016-05-26 12 views
0

私が尋ねる前に、私の壊れた英語のお詫び。Java Spring Boot RESTサービス

現在、私はSpring Bootを使っていくつかのREST Webサービスを開発しています。私はMaven、JPAを使い、データベースにPostgresqlを使用します。 私の問題は、私がを実行したときにエラーがないことがわかりました。正常に起動しました。しかし、私は自分のブラウザにしようとすると、私はエラーを取得:日食の私のコンソールで

This is what i get from browser

、私はこれはエラーのようにログインしました:ここ

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) 
Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 

は私のプロジェクト構造である:

のpom.xml:

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.3.RELEASE</version> 
    <relativePath /> 
    </parent> 

<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.postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.4-1201-jdbc41</version> 
    </dependency> 
    <dependency> 
     <groupId>com.googlecode.json-simple</groupId> 
     <artifactId>json-simple</artifactId> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 
</dependencies> 

<properties> 
    <java.version>1.8</java.version> 
</properties> 


<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> 
       <executable>true</executable> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ejb-plugin</artifactId> 
      <configuration> 
       <ejbVersion>3.0</ejbVersion> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<repositories> 
    <repository> 
     <id>spring-releases</id> 
     <url>https://repo.spring.io/libs-release</url> 
    </repository> 
</repositories> 
<pluginRepositories> 
    <pluginRepository> 
     <id>spring-releases</id> 
     <url>https://repo.spring.io/libs-release</url> 
    </pluginRepository> 
</pluginRepositories> 

Application.java

package com.altoremittance.data; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration; 
import org.springframework.cache.CacheManager; 
import org.springframework.cache.annotation.EnableCaching; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 


@Configuration 
@SpringBootApplication 
@EnableJpaRepositories 
@EnableAutoConfiguration 
@ComponentScan("com.altoremittance.data.service") 
public class Application { 

public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
} 

} 

MemberController.java

package com.altoremittance.data.controller; 

import java.util.List; 

import org.json.simple.JSONObject; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Qualifier; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 
import org.springframework.web.bind.annotation.RestController; 

import com.altoremittance.service.MemberService; 

import com.altoremittance.data.domain.Member; 

@RestController 
@RequestMapping("/member") 
public class MemberController { 

    @Autowired 
    private MemberService memberService; 

    @RequestMapping(value="/addMember", method=RequestMethod.GET,  produces="application/json") 
    public @ResponseBody String getAllMember(){ 

     JSONObject jo = new JSONObject(); 

     jo.put("err_code", "00"); 

     return jo.toString(); 
    } 

} 

MemberRepository.java

package com.altoremittance.service; 

import org.springframework.data.jpa.repository.JpaRepository; 
import org.springframework.stereotype.Component; 
import org.springframework.stereotype.Repository; 

import com.altoremittance.data.domain.Member; 

public interface MemberRepository extends JpaRepository<Member, Long> { 

} 

MemberService.java package com.altoremittance.service;なぜあなたはしようとしている

...

import java.util.List; 

import org.springframework.stereotype.Component; 

import com.altoremittance.data.domain.Member; 

public interface MemberService { 

    public List<Member> findAll(); 

} 

MemberServiceImpl.java

package com.altoremittance.service; 

import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Component; 
import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Transactional; 

import com.altoremittance.data.domain.Member; 

@Service 
@Transactional 
public class MemberServiceImpl implements MemberService { 

    @Autowired 
    private MemberRepository memberRepo; 

    public List<Member> findAll(){ 
     return memberRepo.findAll(); 
    } 

} 
+0

、あなたは/エラーで追加要求のマッピングを持ってみたのですか? –

+0

こんにちはのHardik、ご回答に感謝、 あなたはMemberController.javaでこのように意味するか: @RequestMapping(値= "/エラー"、方法= RequestMethod.GET) \t公共@ResponseBody文字列displayErrorを(){ \t \t \t \tリターン "エラー";あなたの応答のための \t \t \t} –

答えて

0

私はあなたのattached imageを見ていると私はあなたがhttp://localhost:8090/member/getAllMemberにアクセスしようとしていることを見てきましたコントローラ@RequestMappingaddMemberのように定義されている場合、getAllMemberパスへのアクセス?

URLの代わりにhttp://localhost:8090/member/addmemberにアクセスしてください。

これが役に立ちます。

よろしく、Finnally

+0

感謝。 私はこれを更新しましたが、それでも動作しません。 –

+0

こんにちはピーター、あなたは...あなたのコード内で何も更新しないために、HTTP 'へのアクセスのみを必要としません:// localhostを:代わりに前の1の8090 /メンバー/ addmember'のURL ...あなたはあなたについての新しいスクリーンショットを提供することができます請願?よろしくお願いします。 – jcgarcia

0

は、私は@ComponentScanに私のApplication.java

に更新し、問題を知って、私は@ComponentScan( "com.altoremittance")に変更します。

私はこの記事をREFERE: enter link description here

おかげですべてを。@ComponentScan("com.altoremittance")にComponentScan

+0

なぜ '@ Configuration'、' @ EnableAutoconfiguration'などのアノテーションに '@ SpringBootApplication'を一緒に含めていますか? @のSpringBootApplication'が同じである 'ことを知っている[春ブーツのドキュメント](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-using-springbootapplication-annotation)を読みます。 '@ Configuration'、' @ EnableAutoConfiguration'、 '@ ComponentScan'アノテーションを使用します。 – jcgarcia

+0

確かに、私は今それを削除しています...ありがとう@ jcgarcia。 :) –

0

セット。エラー状態として

関連する問題