質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

2回答

2837閲覧

springsecurityのログイン画面について

heavyuseman

総合スコア42

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

1グッド

1クリップ

投稿2017/05/23 13:49

編集2017/05/27 06:37

いつもお世話になっております。
springsecurityでログイン画面を作成しました。
ログイン画面を開き、登録する名前とパスワードを入力し
ログインボタンを押下したところ下記のエラーが出ました

ava.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:278) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:203) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
jacksonの設定はgradleでしております
原因が不明ですのでご教授よろしくお願いいたします。

java

1package com.tuyano.springboot.springsecurity; 2 3import org.springframework.security.config.annotation.web.builders.HttpSecurity; 4import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 5import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7import org.springframework.security.authentication.AuthenticationManager; 8 9 10@EnableWebSecurity 11public class SecurityConfig extends WebSecurityConfigurerAdapter{ 12 13 @Override 14 protected void configure(HttpSecurity http) throws Exception{ 15 http 16 .authorizeRequests() 17 .antMatchers("/first.html").permitAll() 18 .and() 19 .formLogin() 20 .loginPage("/first.html") 21 .loginProcessingUrl("/pricessLogin") 22 .defaultSuccessUrl("/admin.html") 23 .failureUrl("/user.html") 24 .usernameParameter("name") 25 .passwordParameter("password") 26 .and(); 27 28 } 29 @Override 30 public void configure(AuthenticationManagerBuilder auth) throws Exception { 31 auth.inMemoryAuthentication() 32 .withUser("user").password("userpassword").authorities("ROLE_USER"); 33 } 34 35 36}

java

1package com.tuyano.springboot.springsecurity; 2 3import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 5 6public class SecurityWebAppIicationInitializer extends AbstractSecurityWebApplicationInitializer { 7public SecurityWebAppIicationInitializer(){ 8super(SecurityConfig.class); 9 10} 11} 12

java

1package com.tuyano.springboot.app; 2 3import java.util.List; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7import org.springframework.http.MediaType; 8import org.springframework.stereotype.Controller; 9import org.springframework.transaction.annotation.Transactional; 10import org.springframework.ui.Model; 11import org.springframework.web.bind.annotation.ModelAttribute; 12import org.springframework.web.bind.annotation.RequestBody; 13import org.springframework.web.bind.annotation.RequestMapping; 14import org.springframework.web.bind.annotation.RequestMethod; 15import org.springframework.web.bind.annotation.RequestParam; 16import org.springframework.web.bind.annotation.ResponseBody; 17import org.springframework.web.servlet.ModelAndView; 18import com.fasterxml.jackson.databind.SerializationFeature; 19import com.fasterxml.jackson.core.JsonProcessingException; 20import com.fasterxml.jackson.databind.ObjectMapper; 21import com.tuyano.springboot.app.Emp; 22import com.tuyano.springboot.app.EmpRepository; 23import com.tuyano.springboot.dateaccess.DataAccessRepository; 24import com.tuyano.springboot.dateaccess.Newaccount; 25 26 27 28@Controller 29@EnableAutoConfiguration 30public class Test { 31 32 @Autowired //リポジトリを紐づけます 33 EmpRepository repository; 34 @Autowired //リポジトリを紐づけます 35 DataAccessRepository dataAccessRepository; 36 @RequestMapping(value="/") 37 @ResponseBody 38 public String home(){ 39 //json値格納変数 40 String jsonvalue; 41 //全件取得します 42 Iterable<Emp> list = repository.findAll(); 43 44 // 取得した内容を出力します 45 for(Emp emp: list){ 46 //Jacksonでオブジェクトを JSON に変換 47 ObjectMapper objectMapper = new ObjectMapper(); 48 try { 49 jsonvalue = objectMapper.writeValueAsString(emp); 50 System.out.println("jsonの値"+jsonvalue); 51 return jsonvalue; 52 }catch (JsonProcessingException e) { 53 e.printStackTrace(); 54 } 55 } 56 return null; 57 58 } 59 //first画面呼び出し 60 @RequestMapping(value="/first",method=RequestMethod.GET) 61 public String find(){ 62 63 return null; 64 } 65 //NewAccount画面呼び出し 66 @RequestMapping(value="/NewAccount",method=RequestMethod.GET) 67 public String NewAccount(){ 68 69 return null; 70 } 71 //NewAccount画面呼び出し 72 @RequestMapping(value="/NewAccount",method=RequestMethod.POST) 73 @Transactional(readOnly=false) 74 public ModelAndView register(@ModelAttribute("formModel") Newaccount newaccount,ModelAndView mav){ 75 System.out.println("newaccountは"+newaccount); 76 dataAccessRepository.saveAndFlush(newaccount); 77 return new ModelAndView("redirect:/NewAccount"); 78 } 79 80 81}

HTML

1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<title>top page</title> 5<meta http-equiv="Content-Type" 6content="text/html" charset="UTF-8"/> 7 8<!-- css --> 9 10<style> 11 html { height: 100% } 12 body { height: 100%; margin: 0; padding: 0 } 13 #map { height: 100% } 14</style> 15 16 17 18 19</head> 20<body> 21 22 <h1 th:text="${title}">find Page</h1> 23 <table> 24 <form method="post" action="/first"> 25 <tr><td>名前</td> 26 <td><input type="text" id="name" name="name" size="20" th:value="${value}"/></td></tr> 27 <tr><td>パスワード</td> 28 <td><input type="text" id="password" name="password" size="20" th:value="${value}"/></td></tr> 29 <tr><td></td><td><input type="submit" name="onclick" onclick="return Notentered();"/></td></tr> 30 </form> 31 </table> 32 <hr/> 33</body> 34</html>

gradle

1buildscript { 2 ext { 3 springBootVersion = '1.5.1.RELEASE' 4 } 5 repositories { 6 mavenCentral() 7 } 8 dependencies { 9 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 } 11} 12 13apply plugin: 'java' 14apply plugin: 'eclipse-wtp' 15apply plugin: 'org.springframework.boot' 16apply plugin: 'war' 17 18war { 19 baseName = 'MybootApp' 20 version = '0.0.1-SNAPSHOT' 21} 22 23sourceCompatibility = 1.8 24 25repositories { 26 mavenCentral() 27} 28 29configurations { 30 providedRuntime 31} 32 33dependencies { 34 //SpringSecurityを使うため、追加 35 compile('org.springframework.boot:spring-boot-starter-security') 36 compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4') 37 compile('org.springframework.boot:spring-boot-starter-data-jpa') 38 compile('org.springframework.boot:spring-boot-starter-thymeleaf') 39 compile('org.springframework.boot:spring-boot-starter-web') 40 runtime('mysql:mysql-connector-java') 41 providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 42 testCompile('org.springframework.boot:spring-boot-starter-test') 43 // MySQL 44 //compile ("mysql:mysql-connector-java:$mySQLVersion") 45 compile ('com.fasterxml.jackson.core:jackson-databind:2.3.4') 46 compile("org.springframework.boot:spring-boot-starter-thymeleaf") 47 48 49}
A-pZ👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

A-pZ

2017/05/27 06:13

"jacksonの設定はgradleでしております" とのことですが、gradleの内容も記載してくだされば、回答が得られるかもしれません。
heavyuseman

2017/05/27 06:38

いつもご回答ありがとうございます。質問欄にgradleのソースを追記しましたのでご回答宜しくお願い致します
guest

回答2

0

ベストアンサー

動作確認はできていないのですが、jasksonのバージョンがだいぶ古いようです。

spring-boot-starter1.5系では、com.fasterxml.jackson.core は 2.8.8 以降を使うよう定義されていますので、jacksonのビルド設定を解除するか、2.8.8以降を指定するとうまくいくでしょうか。

投稿2017/05/27 12:59

A-pZ

総合スコア12011

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

heavyuseman

2017/05/28 05:51

ご回答ありがとうございます。jasksonのバージョンを2.8.8 以降を設定したところエラーが無事解除しました。ご協力していただきありがとうございました
guest

0

jackson の java.lang.NoSuchMethodError ということで、当てずっぽうですが、getter/setter が無いものがあるとか、Emp にDate や他のBean が使われて、json に変換する際に適切な型に変換できなくなっていませんか?
もしくは、誤ったアノテーションを記述しているとか。

投稿2017/05/27 10:07

NARH

総合スコア209

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

heavyuseman

2017/05/28 05:51

ご回答していただき誠にありがとうございます。jasksonのバージョンを2.8.8 以降を設定したところエラーが無事解除しました。ご協力していただきありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問