[開発] Spring related troubles faced in March, 2017

------------------------------
## 1       
tag: spring-security NoSuchBeanDefinitionException     
 
open-date: 2017/3/13          
trouble:
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined          
 
close-date: 2017/3/13         
shooting:
spring-security.xml
    <'sec:authentication-manager>
        <'sec:authentication-provider user-service-ref="userDetailsService">
            <'sec:password-encoder ref="passwordEncoder" />
        <'/sec:authentication-provider>
    <'/sec:authentication-manager>
userDetailsService
 
UserDetailServiceImpl implements UserDetailsService としていた為、bean名が合致していなかった。
HogeRepositoryをInjectする時は、Interface名でautowiredされてるのと混同してた。ココは普通のref-beanなので真面目なbean名が正解。
 
 
------------------------------
## 2       
tag: spring-security jsp form-login     
 
open-date: 2017/3/13          
trouble:
http://localhost:8080/myProject/login.jsp
Resource Not Found Error!
Resource not found.
 
close-date: 2017/3/13         
shooting:
        <'sec:form-login
            login-page="/login.jsp"
            authentication-failure-url="/login.jsp?error=true" />
としてたのを、以下に修正
        <'sec:form-login
            login-page="/login/loginForm"
            login-processing-url="/login" />
実際のjspは「webapp/WEB-INF/views/login/loginForm.jsp」
 
 
------------------------------
## 3       
tag: spring-security jsp NotReadablePropertyException 
 
open-date: 2017/3/13          
trouble:
NotReadablePropertyException: Invalid property 'principal.account' of bean class [org.springframework.security.authentication.AnonymousAuthenticationToken]: Bean property 'principal.account' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?             
 
close-date: 2017/3/13         
shooting:
JSPで
<'sec:authorize access="isAuthenticated()">
せずに
${f:h(principal.account.firstName)}
した為の例外
 
 
------------------------------
## 4       
tag: jsp CannotRenderException       
 
open-date: 2017/3/13          
trouble:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: An exception occurred processing JSP page /WEB-INF/views/layout/template.jsp at line 27
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/login/loginForm.jsp (line: 4, column: 4) プレフィックス tでインポートされたタグライブラリには、タグ messatePanel は存在しません
 
close-date: 2017/3/13         
shooting:
凡ミス。スペルミス
t:messatePanel --> t:messagesPanel
 
 
------------------------------
## 5       
tag: jsp JasperException    
 
open-date: 2017/3/13          
trouble:
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/login/loginForm.jsp (line: 4, column: 62) Attribute qualified names must be unique within an element          
 
close-date: 2017/3/13         
shooting:
<'t:messagesPanel messagesType="error" messagesType="error" messagesAttributeName="SPRING_SECURITY_LAST_EXCEPTION" />
messagesTypeが重複している。↓↓TOBE
<'t:messagesPanel messagesType="error" messagesAttributeName="SPRING_SECURITY_LAST_EXCEPTION" />
 
 
------------------------------
## 6       
tag: spring-security InternalAuthenticationServiceException          
 
open-date: 2017/3/13          
trouble:
spring-securityの認証項目をusernameでなくuserIdにしたい。
org.springframework.security.authentication.InternalAuthenticationServiceException: For input string: ""
at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:126)
Caused by: java.lang.NumberFormatException: For input string: ""
at account.master.system.pilot.domain.service.userdetails.AmspUserDetailsServiceImpl.loadUserByUsername(AmspUserDetailsServiceImpl.java:29)
 
close-date: 2017/3/13         
shooting:
loginForm.jspのinputのname/idはusernameにするか、小細工が要る。
AFTER:
            <'td><'input type="text" id="username" name="username" value="0001" />(0001)<'/td>
            <'!-- <'td><'input type="text" id="userId" name="userId" value="0001" />(0001)<'/td> -->
もしくは、
JSP ・・・ <'td><'input type="text" id="userId" name="userId" value="0001" />(0001)<'/td>
spring-security.xml ・・・
<'sec:form-login
    login-page="/login/loginForm"
    login-processing-url="/login"
    username-parameter="userId"/>
 
ref.
Spring Security Custom Login Form Annotation Example
https://www.mkyong.com/spring-security/spring-security-custom-login-form-annotation-example/
Spring Bootで認証を行う
http://blog.okazuki.jp/entry/2015/07/05/180726
 
 
------------------------------
## 7       
tag: spring-security TypeException    
 
open-date: 2017/3/13          
trouble:
spring-securityの認証項目をusernameでなくuserIdにしたい。
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
 
close-date: 2017/3/13         
shooting:
なんか術あるんだろうけど、そりあえずの強行手段。 int 型をしぶしぶ String 型に定義しなおす
 
BEFORE
CREATE TABLE ACCOUNT_TBL (
    user_id int(4),
AFTER
CREATE TABLE ACCOUNT_TBL (
    user_id varchar(4),
 
 
------------------------------
## 8       
tag: Git  
 
open-date: 2017/3/14          
trouble:
git  push済みのcommitを揉み消したい      
 
close-date: 2017/3/14         
shooting:
get reset HEAD~
git push -f origin branchname
 
HEADの後の「~」が「直前の」コミットを意味する。2こ前のコミットを指したければ「~~」とする感じ。
 
ref.
git pushを取り消す
http://tweeeety.hateblo.jp/entry/2015/06/10/215753
さっきの取り消したい!って時のGitコマンドまとめ
http://qiita.com/kansiho/items/2bacecdb95d752cb38b7
 
 
------------------------------
## 9       
tag: jsp checkbox NestedServletException CannotRenderException           
 
open-date: 2017/3/14          
trouble:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: java.io.IOException: JSPException including path '/WEB-INF/views/user/registerForm.jsp'.
Caused by: java.io.IOException: JSPException including path '/WEB-INF/views/user/registerForm.jsp'.
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/user/registerForm.jsp (line: 40, column: 16) TLDに従ってタグ form:checkbox は空でなければいけませんが、そうではありません
 
close-date: 2017/3/14         
shooting:
<'form:checkbox path="status" label="ACTV" >ACTV<'/form:checkbox>
↓↓
<'form:checkbox path="status" label="ACTV" />
 
 
------------------------------
## 10     
tag: Spring MVC IllegalStateException            
 
open-date: 2017/3/14          
trouble:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userForm' available as request attribute   
 
close-date: 2017/3/14         
shooting:
Controllerで以下を実装する。
@ModelAttribute
public UserForm setUpForm() {
  UserForm form = new UserForm();
  return form;
}
 
 
------------------------------
## 11     
tag: Spring AOP BeanCreationException BeanCreationException NoSuchBeanDefinitionException        
 
open-date: 2017/3/14          
trouble:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registerController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: account.master.system.pilot.domain.service.user.RegisterService account.master.system.pilot.app.user.RegisterController.registerService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [account.master.system.pilot.domain.service.user.RegisterService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
 
 
close-date: 2017/3/14         
shooting:
public class RegisterServiceImpl implements RegisterService {
↓↓
@Service
public class RegisterServiceImpl implements RegisterService {
 
 
------------------------------
## 12     
tag: jsp JasperException    
 
open-date: 2017/3/14          
trouble:
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/user/registerForm.jsp (line: 10, column: 39) ${ タグが終了していません             
 
close-date: 2017/3/14         
shooting:
<'td><'form:input path="userId" />${f:h{userForm.userId)}<'/td>
↓↓ f:h"{" の括弧が合ってない
<'td><'form:input path="userId" />${f:h(userForm.userId)}<'/td>
 
 
------------------------------
## 13     
tag: jsp checkbox IllegalArgumentException    
 
open-date: 2017/3/14          
trouble:
Caused by: java.lang.IllegalArgumentException: Attribute 'value' is required when binding to non-boolean values  
 
close-date: 2017/3/14         
shooting:
<'form:checkbox path="status" label="INIT" />
↓↓
<'form:checkbox path="status" label="INIT" value="INIT" />
 
 
------------------------------
## 14     
tag: Spring MVC RequestMapping UnsatisfiedServletRequestParameterException    
 
open-date: 2017/3/14          
trouble:
<'form:form action="${pageContext.request.contextPath}/user/register"
method="post" modelAttribute="userForm">
<'form:button>Confirm<'/form:button>
<'/form:form>
 
org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "redo" OR "complete" OR "form" OR "confirm" not met for actual request parameters: register={Submit}, _csrf={c2007699-7c1a-482c-81fc-11858d0cb42f}
 
close-date: 2017/3/14         
shooting:
@Controller
@RequestMapping(value = "/user/register")
public class RegisterController {
public String register(@Valid UserForm userForm, BindingResult bindingResult, Model model, RedirectAttributes attributes) {
↓↓RequestMappingの定義がメソッドに無かった。
@RequestMapping
public String register(@Valid UserForm userForm, BindingResult bindingResult, Model model, RedirectAttributes attributes) {
 
 
------------------------------
## 15     
tag: "spring DateTimeFormat
typeMismatch Date ConversionFailedException
 
open-date: 2017/3/14          
trouble:
Field error in object 'userForm' on field 'birthday': rejected value []; codes [typeMismatch.userForm.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userForm.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'birthday'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value ''; nested exception is java.lang.IllegalArgumentException]  
 
close-date: 2017/3/14         
shooting:
以下のようにformatterを噛ませば良い。
 
@NotNull
@DateTimeFormat(pattern = "yyyy/MM/dd")
private Date birthday;//birthday
 
 
------------------------------
## 16     
tag: Spring redirect RedirectAttributes             
 
open-date: 2017/3/14          
trouble:
Resource Not Found Error!
Resource not found.
 
close-date: 2017/3/14         
shooting:
return "redirect:user/register?complete";
↓↓
return "redirect:/user/register?complete";
 
 
------------------------------
## 17     
tag: xml util schema           
 
open-date: 2017/3/14          
trouble:
Description Resource Path Location Type
The prefix "util" for element "util:map" is not bound. myproject-codelist.xml /myproject-domain/src/main/resources/META-INF/spring line 29 XML Problem
 
 
close-date: 2017/3/14         
shooting:
xmlの冒頭にschema定義にutilを追加する
 
<'beans xmlns=
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
    ">
 
 
------------------------------
## 18     
tag: TERASOLUNA SimpleMapCodeList          
 
open-date: 2017/3/14          
trouble:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.terasoluna.gfw.common.codelist.SimpleMapCodeList' is defined         
 
close-date: 2017/3/14         
shooting:
<'bean id="CL_ROLE" parent="org.terasoluna.gfw.common.codelist.SimpleMapCodeList">
↓↓
<'bean id="CL_ROLE" class="org.terasoluna.gfw.common.codelist.SimpleMapCodeList">
 
cf. DBから取得する場合は「parent="AbstractJdbcCodeList"」とparentでOK
 
 
------------------------------
## 19     
tag: Spring xml IllegalArgumentException ClassNotFoundException           
 
open-date: 2017/3/14          
trouble:
Caused by: java.lang.IllegalArgumentException: Cannot find class [java.util.linkedHashMap]
Caused by: java.lang.ClassNotFoundException: java.util.linkedHashMap
 
close-date: 2017/3/14         
shooting:
単なるミスペル
 
<'util:map key-type="java.lang.String" value-type="java.lang.String"
map-class="java.util.linkedHashMap">
↓↓
map-class="java.util.LinkedHashMap">
 
 
------------------------------
## 20     
tag: Spring MVC DefaultMessageSourceResolvabl        
 
open-date: 2017/3/15          
trouble:
org.springframework.context.support.DefaultMessageSourceResolvable: codes [userForm.birthday,birthday]; arguments []; default message [birthday]         
 
close-date: 2017/3/15         
shooting:
JSP では text で受けているのに対し、Form は Date 型で宣言している為。
Form の方を String にすれば良し。
 
 
------------------------------
## 21     
tag: Spring MVC  
 
open-date: 2017/3/15          
trouble:
form の validation の NotNull を通過してしまう、無入力でsubmitしているのに。          
 
close-date: 2017/3/15         
shooting:
無入力でも空文字が渡っている為。NotBlankなvalidationも付ければ良い。
 
 
------------------------------
## 22     
tag: Spring MVC validation 
 
open-date: 2017/3/16          
trouble:
4文字以上って設定しただけなのに、エラーメッセージが「size must be between 4 and 2147483647」と出る。
2147483647 は最大値と思われる。
 
close-date: 2017/3/16         
shooting:
@Size(min = 4)
private String password;//password
としていた為の事象。Sizeでやるなら @Size(min=4, max=8)な書き方にすべき。
最小値だけの指定であれば↓以下が正解
@Min(value = 4)
private String password;//password
というか、数値じゃなくて文字列数なのでMinも違う説w
文字列数はSizeで良いぽい。

tag : Spring

2017-03-23 22:02 : 開発 : コメント : 0 : トラックバック : 0 :
コメントの投稿
非公開コメント

« next  ホーム  prev »

search

ad



counter


tag cloud

category cloud