将CAS存储到数据库中

时间:2014-03-21 07:17:16

标签: java mysql cas

我尝试在MySQL中执行JpaTicketRegistry Store,请遵循以下文章: https://wiki.jasig.org/display/CASUM/JpaTicketRegistry#JpaTicketRegistry-AvoidingDeadlocks

deployerConfigContext.xml里

    <!-- 
    Sample, in-memory data store for the ServiceRegistry. A real implementation
    would probably want to replace this with the JPA-backed ServiceRegistry DAO
    The name of this bean should remain "serviceRegistryDao".
     -->
    <!-- <bean id="serviceRegistryDao" class="org.jasig.cas.services.JpaServiceRegistryDaoImpl"
                            p:entityManagerFactory-ref="entityManagerFactory" /> -->

<!--    <bean
        id="serviceRegistryDao"
        class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl" /> -->
<bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <property name="jpaVendorAdapter">
   <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="generateDdl" value="true"/>
    <property name="showSql" value="true" />
   </bean>
  </property>
  <property name="jpaProperties">
   <props>
    <!-- Use MySQLDialect at your own risk. See MySQL section below for details. 
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> -->
    <!-- For MySQL 5.x, use the following instead -->
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>

    <prop key="hibernate.hbm2ddl.auto">update</prop>

   </props>
  </property>
 </bean>

 <bean id="transactionManager"
  class="org.springframework.orm.jpa.JpaTransactionManager"
  p:entityManagerFactory-ref="entityManagerFactory" />

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

 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource"
  p:driverClassName="com.mysql.jdbc.Driver"
  p:url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
  p:password="root"
  p:username="root" />

ticketRegistry.xml

<!-- Ticket Registry -->
 <!-- <bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.JpaTicketRegistry" /> -->

 <!--
  Injects EntityManager/Factory instances into beans with
  @PersistenceUnit and @PersistenceContext
 -->
 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

 <!-- Use the following for versions prior to 3.4.11 -->

 <bean id="ticketRegistry"
  class="org.jasig.cas.ticket.registry.JpaTicketRegistry">
  <constructor-arg index="0" ref="entityManagerFactory" />
 </bean>


 <!-- TICKET REGISTRY CLEANER -->
 <bean id="ticketRegistryCleaner"
  class="org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner"
  p:ticketRegistry-ref="ticketRegistry"
  p:lock-ref="cleanerLock" />

 <!--
 Use JpaLockingStrategy for 3.4.11 and later.
 This bean is only needed for HA setups where multiple nodes are attempting
 cleanup on a shared database, but it doesn't substantially impact performance
 and is easy to setup and is therefore recommended for all JpaTicketRegistry deployments.
 This component automatically creates the LOCKS table so no further configuration
 is required.

 <bean id="cleanerLock"
  class="org.jasig.cas.ticket.registry.support.JpaLockingStrategy"
  p:uniqueId="${host.name}"
  p:applicationId="cas-ticket-registry-cleaner" /> -->

 <!--
  Use JdbcLockingStrategy on 3.4.10 and before for HA setups where multiple nodes are attempting
  cleanup on a shared database. This bean requires additional configuration:
  1. Creation of LOCKS table (see below)
  2. Setting ticket.cleaner.database.platform property
  Note that the ticket.cleaner.database.platform property should be set in cas.properties
  or some other properties file that is loaded by a PropertyPlaceholderConfigurer bean in
  the Spring context.
  Allowed values for ticket.cleaner.database.platform:
   * SqlServer for Microsoft SQL Server
   * HSQL for HSQLDB
   * SQL92 for any platform that supports the SQL-92 FOR UPDATE clause. (e.g. PostgreSQL, Oracle)
 -->

 <bean id="cleanerLock"
  class="org.jasig.cas.ticket.registry.support.JdbcLockingStrategy"
  p:uniqueId="${host.name}"
  p:platform="${ticket.cleaner.database.platform}"
  p:applicationId="cas-ticket-registry-cleaner"
  p:dataSource-ref="dataSource" />


 <bean id="ticketRegistryCleanerJobDetail"
  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
  p:targetObject-ref="ticketRegistryCleaner"
  p:targetMethod="clean" />

 <bean id="periodicTicketRegistryCleanerTrigger"
  class="org.springframework.scheduling.quartz.SimpleTriggerBean"
  p:jobDetail-ref="ticketRegistryCleanerJobDetail"
  p:startDelay="20000"
  p:repeatInterval="1800000" />

cas版

cas-client-core-3.1.10.jar
cas-server-integration-jboss-3.3.5.jar

catalina.out中

21/03/2014 14:11:00 [10.61.203.192-startStop-1] DEBUG [DelegatingFilterProxy] Initializing filter 'springSecurityFilterChain'
Mar 21, 2014 2:11:00 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistryCleaner' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Cannot resolve reference to bean 'cleanerLock' while setting bean property 'lock'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.jasig.cas.ticket.registry.support.JdbcLockingStrategy] for bean with name 'cleanerLock' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]; nested exception is java.lang.ClassNotFoundException: org.jasig.cas.ticket.registry.support.JdbcLockingStrategy
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:62)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.jasig.cas.ticket.registry.support.JdbcLockingStrategy] for bean with name 'cleanerLock' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]; nested exception is java.lang.ClassNotFoundException: org.jasig.cas.ticket.registry.support.JdbcLockingStrategy
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1105)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:386)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    ... 32 more
Caused by: java.lang.ClassNotFoundException: org.jasig.cas.ticket.registry.support.JdbcLockingStrategy
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
    ... 42 more

21/03/2014 14:11:00 [10.61.203.192-startStop-1] DEBUG [ClientInfoThreadLocalFilter] Initializing filter 'CAS Client Info Logging Filter'

问题:为什么会发生异常?

1 个答案:

答案 0 :(得分:1)

从您的堆栈跟踪中,您似乎错过了cas-server-support-jdbc插件。 (您可以在github看到哪个类属于哪个插件。)

在lib中包含.jar可以解决问题。

如果您没有使用maven war overlay method来检索您的依赖项,您仍然可以搜索direct downloads的存储库镜像。