Spring Security initially require more than a few tries to login

I am using

  • egovframework (sort of spring framework) 3.6
  • Spring Security (core,web,config,taglibs) 4.1.1.Release.
  • servlet-api 2.5
  • ojdbc7
  • commons-dbcp 1.4
  • WAS : Tomcat 7.0.79
  • database : Oracle 12C ( basic setup no additional configuration out of box)

The problem I am having is that login page requires more than one time login id and password to login every morning. I am suspecting that there are problems with initial database connection problem with spring security. After first login, the login problem disappears but it happens next day.
I can’t find any error in my configuration. but I really hope you can find it.

context-datasource.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/jdbc  http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd">
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
            <property name="url" value="#{propertyConfigurer['db.conn']}" />
            <property name="username" value="userId" />
            <property name="password" value="password" />
            <property name="initialSize" value="5"></property>
            <property name="maxActive" value="20"></property>
            <property name="minIdle" value="5"></property>
        </bean>
    </beans> 

context-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

        <security:http use-expressions="true" auto-config="true" >

           <security:headers>
                   <security:frame-options  disabled="true"></security:frame-options>
           </security:headers>
        <security:form-login login-page="/loginPage.do" 
                login-processing-url="/login.do"
                username-parameter="user_id"
                password-parameter="user_pwd"
                authentication-failure-url="/loginPage.do?result=fail"
                authentication-success-forward-url="/loginSuccess"

                />
        <security:logout invalidate-session="true" logout-url="/logout" logout-success-url="/loginPage.do"/>
        <security:access-denied-handler error-page="/mainWatchPage.do" />

        <security:csrf disabled="true"/>

    </security:http>
<security:authentication-manager>
        <security:authentication-provider>
            <security:jdbc-user-service id="userSecurity" data-source-ref="dataSource" 
                users-by-username-query="SELECT USER_ID username, USER_PASSWD password, USE_YN enabled FROM SF_USER_TBALE WHERE USER_ID=?" 
                authorities-by-username-query="SELECT USER_ID username, 'ROLE_'||USER_GRADE role FROM SF_USER_TBALE WHERE USER_ID=?" 

            />
            <!--  <security:password-encoder hash="{sha}"/>-->
        </security:authentication-provider>
    </security:authentication-manager>

</beans>

web.xml

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”
id=”WebApp_ID” version=”2.5″>
gisweb

<!-- spring security config -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>encodingFilter</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>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>

<filter>
    <filter-name>HTMLTagFilter</filter-name>
    <filter-class>egovframework.rte.ptl.mvc.filter.HTMLTagFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>HTMLTagFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>

<error-page>
    <error-code>403</error-code>
    <location>/</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/</location>
</error-page>
<error-page>
    <error-code>405</error-code>
    <location>/</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/</location>
</error-page>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:egovframework/spring/context-*.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/egovframework/springmvc/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

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

<login-config>
    <auth-method>BASIC</auth-method>
</login-config>

I added four line at the bottom of context-datasource.xml because I read from Oracle stale connection However it seems like it is not working

<property name="validationQuery"  value="SELECT 1 FROM DUAL"></property>
<property name="testOnBorrow" value="false"></property>
<property name="testOnReturn" value="false"></property>
<property name="testWhileIdle" value="true"></property>