Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring身份验证随机停止响应并阻止应用程序访问_Java_Spring_Spring Mvc_Authentication_Spring Security - Fatal编程技术网

Java Spring身份验证随机停止响应并阻止应用程序访问

Java Spring身份验证随机停止响应并阻止应用程序访问,java,spring,spring-mvc,authentication,spring-security,Java,Spring,Spring Mvc,Authentication,Spring Security,基于Spring安全认证的Web应用程序存在问题。过去,当测试用户数量很少时,它工作得很好。然而,一旦我们上线,用户数量增加,我们就开始体验到spring身份验证的奇怪问题。因为我们使用的是负载均衡器,并且在多个amazon上都有应用程序。应用程序重启只能暂时解决问题。我们打开了调试日志记录,但它没有指出任何具体问题 这里是我们的spring security context.xml xml是 Spring身份验证服务 尝试使用OpenID身份验证登录时的日志 尝试使用Spring安全身份验证登

基于Spring安全认证的Web应用程序存在问题。过去,当测试用户数量很少时,它工作得很好。然而,一旦我们上线,用户数量增加,我们就开始体验到spring身份验证的奇怪问题。因为我们使用的是负载均衡器,并且在多个amazon上都有应用程序。应用程序重启只能暂时解决问题。我们打开了调试日志记录,但它没有指出任何具体问题

这里是我们的spring security context.xml

xml是

Spring身份验证服务

尝试使用OpenID身份验证登录时的日志

尝试使用Spring安全身份验证登录时的日志

线程堆栈

我希望有人知道可能是什么问题

谢谢

更新: 休眠配置

public PropertiesFactoryBean hibernateProperties() {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    Properties properties = createHibernateProperties();
    propertiesFactoryBean.setProperties(properties);
    return propertiesFactoryBean;
}

private Properties createHibernateProperties() {
    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
    properties.setProperty("hibernate.show_sql", false);
    properties.setProperty("hibernate.max_fetch_depth", 0);
    properties.setProperty("hibernate.hbm2ddl.auto", validate);
    properties.setProperty("hibernate.jdbc.batch_size", 50);
    properties.setProperty("hibernate.connection.pool_size", 200);
    properties.setProperty("hibernate.connection.charSet", "UTF-8");
    properties.setProperty("hibernate.connection.characterEncoding", "UTF-8");
    properties.setProperty("hibernate.connection.useUnicode", true);
    properties.setProperty("hibernate.connection.autocommit", false);
    properties.setProperty("hibernate.cache.use_second_level_cache",true);
    properties.setProperty("hibernate.cache.use_query_cache", true);
    properties.setProperty("hibernate.cache.use_structured_entries", true);
    properties.setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.EhCacheRegionFactory");
    return properties;
}

@Bean (destroyMethod = "close")
public ComboPooledDataSource dataSource() {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    try {
        dataSource.setDriverClass(Settings.getInstance().config.database.driver);
        dataSource.setJdbcUrl(Settings.getInstance().config.database.url+"?useUnicode=true&characterEncoding=UTF-8");
        dataSource.setUser(Settings.getInstance().config.database.user);
        dataSource.setPassword(Settings.getInstance().config.database.password);

        dataSource.setAcquireIncrement(10);
        dataSource.setInitialPoolSize(5);
        dataSource.setMinPoolSize(5);
        dataSource.setMaxPoolSize(50);
        dataSource.setMaxStatements(50);
        dataSource.setMaxIdleTime(3000);
        dataSource.setAutomaticTestTable("testTable");

    } catch (PropertyVetoException e) {
        logger.error(e);
    }

    return dataSource;
}
休眠上下文:

<!-- Adding exception translation to a template-less Hibernate DAO  -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- Hibernate SessionFactory for the datasource -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties" ref="hibernateProperties" />
    <property name="packagesToScan">
        <list>
            <value>org.prosolo.domainmodel</value>
            <value>org.prosolo.services.logging.domain</value>
            <value>org.prosolo.services.tree.settings.model</value>
        </list>
    </property>
    <property name="namingStrategy">
        <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
    </property>
</bean>
与数据源相关的Spring配置:

<!-- TRANSACTION CONFIGURATION -->

    <!-- Allowing annotation-driven transactions -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="transactionTemplate"
        class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager" />
    </bean>

    <bean id="taskExecutor"
        class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="corePoolSize" value="5" />
        <property name="maxPoolSize" value="10" />
        <property name="WaitForTasksToCompleteOnShutdown" value="true" />
    </bean>

    <!-- Error retry advice -->
    <aop:config>
        <aop:pointcut id="transactional"
            expression="execution(* org.prosolo.services.general.impl.AbstractManagerImpl.saveEntity(..))" />
        <aop:advisor pointcut-ref="transactional" advice-ref="retryAdvice"
            order="-1" />
    </aop:config>

    <bean id="retryAdvice"
        class="org.springframework.retry.interceptor.RetryOperationsInterceptor" />

事实证明,M.Deinum关于连接池不足的评论是正确的。我对这个问题的解决方案是用Tomcat池数据源替换c3p0数据源。在这次改变之后,我再也没有这个问题了。更新版本如下所示

    @Bean (destroyMethod = "close")
public DataSource dataSource() {

    PoolProperties p = new PoolProperties();
    p.setUrl(Settings.getInstance().config.database.url+"?useUnicode=true&characterEncoding=UTF-8");
    p.setDriverClassName(Settings.getInstance().config.database.driver);
    p.setUsername(Settings.getInstance().config.database.user);
    p.setPassword(Settings.getInstance().config.database.password);
    p.setJmxEnabled(false);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
            + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;"
            + "org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer");
         org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();
         ds.setPoolProperties(p);
         return ds;
 }

根据您在这里发布的内容,我的猜测是数据源使用错误或缺少/不正确的事务配置。导致游泳池饥饿。你能说得更具体些吗?数据源出了什么问题,我应该更改什么?我不知道出了什么问题,但从您在这里发布的内容判断,YOUR池非常匮乏。需要更改的内容我不知道,因为没有代码、配置等。如果您自己乱搞数据源,或者自己打开hibernate会话/EntityManager,我有一个建议不要这样做。谢谢您的评论。我编辑了原始帖子以包含我的休眠设置。如果您是根据线程堆栈得出这个结论的,或者有任何其他迹象表明数据库连接存在问题,请告诉我。我问这个是因为我不知道应该在哪里调查。另外,还有一个问题。如果存在池饥饿,并且我从负载平衡器中删除了我的实例,因此没有应用程序使用,这不是假设连接在某个点再次可用吗?