Module incompatibility

273 views
Skip to first unread message

Mitchell Bösecke

unread,
Jan 20, 2023, 1:20:56 AM1/20/23
to CAS Community
Is there no bug tracker for this project to report bugs??

I found an incompatibility between libraries. The addition of ""org.apereo.cas:cas-server-support-pm-jdbc"" will prevent you from also adding either of the following:
  • "org.apereo.cas:cas-server-support-events-jpa"
  • "org.apereo.cas:cas-server-support-jpa-ticket-registry"
In both cases you get a stack trace during application startup saying the following:

Caused by: java.lang.ClassCastException: class org.springframework.beans.factory.support.NullBean cannot be cast to class javax.persistence.EntityManagerFactory (org.springframework.beans.factory.support.NullBean and javax.persistence.EntityManagerFactory are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @277050dc)

To replicate:

I start a new project using the CAS Initializer and version 6.6.4:

mkdir cas-test
cd cas-test
curl -k https://casinit.herokuapp.com/starter.tgz -d casVersion=6.6.4 -d dependencies="core" | tar -xzvf -

Add the following into the gradle.build file within the "dependencies" section:

implementation "org.apereo.cas:cas-server-support-pm-webflow"
implementation "org.apereo.cas:cas-server-support-pm-jdbc"

implementation "org.apereo.cas:cas-server-support-jpa-ticket-registry"

And update /etc/cas/config/cas.properties to have some basic setup:

server.port=8444

cas.ticket.registry.jpa.driver-class=org.postgresql.Driver
cas.ticket.registry.jpa.dialect=org.hibernate.dialect.PostgreSQL10Dialect
cas.ticket.registry.jpa.enabled=true
cas.ticket.registry.jpa.user=redacted
cas.ticket.registry.jpa.password=redacted
cas.ticket.registry.jpa.url=jdbc:postgresql://redacted

Try to startup the application and it fails. If you remove the "support-pm-jdbc" module from the gradle file, it will startup just fine.

Mitchell Bösecke

unread,
Feb 29, 2024, 9:53:47 AM2/29/24
to Andrea Colajacomo, CAS Community
Unfortunately no I have not solved this.

On Thu, Feb 29, 2024, 7:51 AM Andrea Colajacomo <andrea.c...@alecsandria.it> wrote:
Hello Mitchell,
had you solved this issue?

It seems to be still present also on version 7

Bye
Andrea

Andrea Colajacomo

unread,
Feb 29, 2024, 9:53:48 AM2/29/24
to CAS Community, Mitchell Bösecke
Hello Mitchell,
had you solved this issue?

It seems to be still present also on version 7

Bye
Andrea


Il giorno venerdì 20 gennaio 2023 alle 07:20:56 UTC+1 Mitchell Bösecke ha scritto:

Andrea Colajacomo

unread,
Feb 29, 2024, 10:50:23 AM2/29/24
to Mitchell Bösecke, CAS Community
Ok,
so we are in two in searching for a solution
😟

Trent Edwards

unread,
Mar 18, 2025, 11:16:37 PM3/18/25
to CAS Community, Andrea Colajacomo, CAS Community, Mitchell Bösecke
Has anybody found a solution for this? I'm on CAS 7.0.10 and I have this same issue.

Trent Edwards

unread,
Mar 28, 2025, 12:04:29 PM3/28/25
to CAS Community, Trent Edwards, Andrea Colajacomo, CAS Community, Mitchell Bösecke
I ended up with this solution:

I added this to resources/META-INF/spring.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.mycasconfig.TicketRegistryConfiguration

I added this to ect/cas/config/cas.properties:
spring.main.allow-bean-definition-overriding=true
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,org.apereo.cas.config.JpaTicketRegistryConfiguration
spring.component-scan.base-packages=org.mycasconfig
And here is the Configuration file that overrides and provides the EntityManager:
package org.mycasconfig;

import com.zaxxer.hikari.HikariDataSource;
import java.time.Duration;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

@Configuration("ticketRegistryConfiguration")
@EnableTransactionManagement
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class TicketRegistryConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(TicketRegistryConfiguration.class);

@Bean(name = "ticketDataSource")
public DataSource ticketDataSource(final CasConfigurationProperties casProperties) {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setSchema(casProperties.getTicket().getRegistry().getJpa().getDefaultSchema());
dataSource.setJdbcUrl(casProperties.getTicket().getRegistry().getJpa().getUrl());
dataSource.setUsername(casProperties.getTicket().getRegistry().getJpa().getUser());
dataSource.setPassword(casProperties.getTicket().getRegistry().getJpa().getPassword());
dataSource.setDriverClassName(casProperties.getTicket().getRegistry().getJpa().getDriverClass());
dataSource.setMaximumPoolSize(casProperties.getTicket().getRegistry().getJpa().getPool().getMaxSize());
dataSource.setMinimumIdle(casProperties.getTicket().getRegistry().getJpa().getPool().getMinSize());
dataSource.setMaxLifetime(Duration.parse(casProperties.getTicket().getRegistry().getJpa().getPool().getMaximumLifetime()).toMillis());
dataSource.setAutoCommit(casProperties.getTicket().getRegistry().getJpa().isAutocommit());
LOGGER.info("Ticket DataSource configured with URL: {}", dataSource.getJdbcUrl()); // Done
return dataSource;
}

@Bean(name = "ticketRegistryJpaVendorAdapter")
public HibernateJpaVendorAdapter ticketRegistryJpaVendorAdapter(final CasConfigurationProperties casProperties) {
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabasePlatform(casProperties.getTicket().getRegistry().getJpa().getDialect());
adapter.setGenerateDdl(casProperties.getJdbc().isGenDdl());
adapter.setShowSql(casProperties.getJdbc().isShowSql());
LOGGER.info("TicketRegistry JpaVendorAdapter configured with dialect {}", adapter.getJpaDialect()); // Done
return adapter;
}

@Bean(name = "ticketEntityManagerFactory")
@Primary
public LocalContainerEntityManagerFactoryBean ticketEntityManagerFactory(Environment environment,
final CasConfigurationProperties casProperties,
@Qualifier("ticketDataSource") DataSource ticketDataSource,
@Qualifier("ticketRegistryJpaVendorAdapter") HibernateJpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(ticketDataSource);
emf.setPackagesToScan("org.apereo.cas.ticket");
emf.setJpaVendorAdapter(jpaVendorAdapter);
emf.setPersistenceUnitName("jpaTicketRegistryContext");
emf.getJpaPropertyMap().put("hibernate.dialect", casProperties.getTicket().getRegistry().getJpa().getDialect());
emf.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", casProperties.getTicket().getRegistry().getJpa().getDdlAuto());
emf.getJpaPropertyMap().put("hibernate.show_sql", environment.getProperty("hibernate.show_sql", Boolean.class, false));
emf.getJpaPropertyMap().put("hibernate.format_sql", environment.getProperty("hibernate.format_sql", Boolean.class, false));

// Ensure initialization
emf.afterPropertiesSet(); // Force initialization to catch errors early
LOGGER.info("Ticket EntityManagerFactory configured with DataSource: {}", ticketDataSource); // Done
return emf;
}

@Bean(name = "ticketEntityManagerFactoryInstance")
public EntityManagerFactory ticketEntityManagerFactoryInstance(
@Qualifier("ticketEntityManagerFactory") LocalContainerEntityManagerFactoryBean emfBean) {
EntityManagerFactory emf = emfBean.getObject();
if (emf == null) {
LOGGER.error("EntityManagerFactory is null! Check DataSource and JPA configuration.");
throw new IllegalStateException("Failed to initialize EntityManagerFactory for JpaTicketRegistry");
}
LOGGER.info("ticketEntityManagerFactoryInstance successfully created: {}", emf);
return emf;
}

@Bean
public JpaTransactionManager transactionManager(
@Qualifier("ticketEntityManagerFactoryInstance") EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
LOGGER.info("TransactionManager configured with EntityManagerFactory: {}", entityManagerFactory);
return transactionManager;
}

}

Reply all
Reply to author
Forward
0 new messages