Hello,

CAS6 and CAS5 are different, but they both disable
DataSourceAutoConfiguration, so we need to configure database ourselves.

this is what I do.  under org.apereo.cas.config package.  And then,  under
spring.factories, include it in auto-configuration:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
............MyConfiguration....

Hope that works.

Yan

@Configuration("MyDatabaseConfiguration")
@EnableJpaRepositories(
   entityManagerFactoryRef = "entityManagerFactory",
   basePackages = { "....................."}  // packages where repository
live
)
public class MyDatabaseConfiguration  {
private static final Logger logger =
LoggerFactory.getLogger(QuestDatabaseConfiguration.class);


@Bean(name = "casDataSource")
    protected DataSource casDS() {
    try {
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
bean.setJndiName("java:comp/.........");
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(false);
bean.afterPropertiesSet();
return (DataSource)bean.getObject();
    } catch (Exception ex) {
    logger.error("Cannot find datasource.", ex);
    return null;
    }
    }

    @Bean(name = "entityManagerFactory")
    public EntityManagerFactory entityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

LocalContainerEntityManagerFactoryBean factory = new
LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setJpaProperties(additionalProperties());

// packages where entities live
factory.setPackagesToScan(new String[] {"..................."});

factory.setDataSource(casDS());
factory.afterPropertiesSet();

return factory.getObject();
    }

    Properties additionalProperties() {
        Properties properties = new Properties();
        properties.setProperty(
          "hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");

        return properties;
    }

    @Bean
    public PlatformTransactionManager transactionManager(
    @Qualifier("entityManagerFactory") EntityManagerFactory emf) {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(emf);
        return txManager;
    }


On Mon, Aug 30, 2021 at 4:12 AM Ivan Green <frych...@gmail.com> wrote:

> Hello!
>
> I would be very grateful for your help.
>
> Faced the same problem on CAS 5.2.3.
>
> I am using spring data jpa.
>
> In the application.properties file, I described the connection to the
> database through the standard:
>
> spring.datasource.url =
> spring.datasource.username =
> spring.datasource.password =
> spring.jpa.show-sql =
> spring.jpa.hibernate.ddl-auto =
> spring.jpa.properties.hibernate.dialect =
>
> Next, I created entities and repository extends CrudRepository.
>
> When trying to @Autowired my repos in services, I get a
> NoSuchBeanDefinition error.
>
> The configuration goes through the spring.factories file:
>
> org.springframework.boot.autoconfigure.EnableAutoConfiguration =
> ru.test.security.core.cas.config.CasMainPropertiesConfig
>
> CasMainPropertiesConfig, which contains:
>
> @Configuration ("ConfigurationName")
> @EnableConfigurationProperties (CasConfigurationProperties.class)
> @ComponentScan ("ru.test.security.core")
> @PropertySource ("file: C /.../ cas.standalone.properties")
> public class CasMainPropertiesConfig {
>
> }
>
> When trying to insert @EnableJpaRepository or @EntityScan here, the
> application simply does not start with an error:
>
> [org.apereo.cas.web.CasWebApplicationContext] - <Exception encountered
> during context initialization - cancelling refresh attempt:
> org.springframework.beans.factory.BeanDefinitionStoreException: Failed to
> process import candidates for configuration class [org.apereo.cas.web.
> CasWebApplication]; nested exception is java.lang.NoClassDefFoundError: org
> / springframework / data / repository / config / BootstrapMode>
>
> What's going wrong? Tried adding -Dspring.index.ignore = true to run and
> nothing changes.
>
> I hope very much for your help.
>
> суббота, 15 мая 2021 г. в 00:10:12 UTC+3, Yan Zhou:
>
>> I figured out before I was about to give up.  All I had to do is:
>> -Dspring.index.ignore=true    add this to startup script.
>>
>> Spring 5 has this new feature that CAS builds on, it won’t load JPA
>> repository beans unless one of its modules has it included in
>> META-INF/spring.components
>>
>>  Once I understood that, I can follow CAS framework to get it done
>> without using that flag.
>>
>> On Thursday, May 13, 2021 at 9:55:00 PM UTC-4 Pablo Vidaurri wrote:
>>
>>> I assume you are also using
>>> org.springframework.boot:spring-boot-starter-data-jpa
>>>
>>> or is there a special CAS dependency to use instead?
>>>
>>> On Thursday, May 13, 2021 at 5:42:23 PM UTC-5 Yan Zhou wrote:
>>>
>>>> Hello,
>>>>
>>>> I am about to give up, and stay with jdbcTemplate.  I am unable to get
>>>> Spring JPA Data Repository to work with CAS 6.4 snapshot.
>>>>
>>>> This is my CasWebApplication, everything about data repository is
>>>> enabled. But there is no indication in logs that data-jpa autoConfiguration
>>>> is taking place.
>>>>
>>>> @SpringBootApplication(
>>>> scanBasePackages  = {"org.apereo.cas", "com.quest.cas"},
>>>> exclude = {
>>>>     GroovyTemplateAutoConfiguration.class
>>>> },
>>>> proxyBeanMethods = false)
>>>> @EnableJpaRepositories(basePackages = {"com.quest.cas.prs.model"})
>>>> @EntityScan(basePackages =  {"com.quest.cas.prs.model"})
>>>> @EnableConfigurationProperties(CasConfigurationProperties.class)
>>>> @EnableAsync
>>>> @EnableAspectJAutoProxy(proxyTargetClass = true)
>>>> @EnableTransactionManagement(proxyTargetClass = true)
>>>> @EnableScheduling
>>>> @NoArgsConstructor
>>>> @Slf4j
>>>> public class CasWebApplication {
>>>>
>>>>
>>>> There must be something preventing Data repository running, see below
>>>> for some conditions from Spring,  I think my runtime environment should
>>>> allow it to run, but it does not.
>>>>
>>>> @Configuration(proxyBeanMethods = false)
>>>> @ConditionalOnBean(DataSource.class)
>>>> @ConditionalOnClass(JpaRepository.class)
>>>> @ConditionalOnMissingBean({ JpaRepositoryFactoryBean.class,
>>>> JpaRepositoryConfigExtension.class })
>>>> @ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name =
>>>> "enabled", havingValue = "true",
>>>> matchIfMissing = true)
>>>> @Import(JpaRepositoriesRegistrar.class)
>>>> @AutoConfigureAfter({ HibernateJpaAutoConfiguration.class,
>>>> TaskExecutionAutoConfiguration.class })
>>>> public class JpaRepositoriesAutoConfiguration {
>>>>
>>>> Yan
>>>>
>>>>
>>>> On Wednesday, May 12, 2021 at 2:33:07 PM UTC-4 Pablo Vidaurri wrote:
>>>>
>>>>> Having same problem with the autowire of the repository annotated
>>>>> class. Any help would be appreciated.
>>>>>
>>>>> -psv
>>>>>
>>>>> On Tuesday, May 11, 2021 at 8:43:05 AM UTC-5 Yan Zhou wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> CAS uses Spring JdbcTemplate, it does not use Spring JPA Data
>>>>>> Repository. I was able to easily add that in CAS 5.3, but run into
>>>>>> difficulty with CAS 6.3.
>>>>>>
>>>>>> The Spring JPA Data Repository allows me to define interface and
>>>>>> Spring provides beans that implement them and Spring cares for all the
>>>>>> injection.   In Cas 6.3, I keep getting error: NoSuchBeanDefinition, in
>>>>>> other words, Spring did not instantiate beans for repository interfaces 
>>>>>> as
>>>>>> it should.
>>>>>>
>>>>>> I believe all my Spring Data Repository configuration is correct and
>>>>>> that is why it is working in CAS5.3, such as the spring-data-jpa
>>>>>> dependencies, specifying packages for @EnableJpaRepository, @EntityScan 
>>>>>> in
>>>>>> a @Configuration class.
>>>>>>
>>>>>> Here is CAS 5.3. I can see Spring is instantiating beans for
>>>>>> repository interfaces, but this is not happening in CAS 6.3
>>>>>>
>>>>>> Did the wiring and bean instantiation change in cas 6.3?
>>>>>>
>>>>>> Thanks,
>>>>>> Yan
>>>>>>
>>>>>> 2021-05-11 02:00:29,041 DEBUG
>>>>>> [org.springframework.beans.factory.support.DefaultListableBeanFactory] -
>>>>>> <Pre-instantiating singletons in
>>>>>> org.springframework.beans.factory.support.DefaultListableBeanFactory@66345a4f:
>>>>>> defining beans  ............. (some of them are the JPA Data Repository
>>>>>> beans)
>>>>>>
>>>>>

-- 
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
--- 
You received this message because you are subscribed to the Google Groups "CAS 
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cas-user+unsubscr...@apereo.org.
To view this discussion on the web visit 
https://groups.google.com/a/apereo.org/d/msgid/cas-user/CAFSoZekHSwjKHx3A06Xm%3DrDpw8hH_%3DrFmHQLZ4uAvx5-z__xNw%40mail.gmail.com.

Reply via email to