Why does CAS Spring Web Application Context Appear To Refresh?

762 views
Skip to first unread message

William

unread,
Oct 6, 2016, 6:33:53 PM10/6/16
to CAS Community
I am running CAS 5.0 RC4 on Apache Tomcat 8.0.37 on Centos 7 (Linux).

I saw another post from Philippe Marasse titled "Issue with json service registry between CASv5 RC3-SNAP and RC4-SNAP" yesterday that looks exactly like my issue.  He was using Tomcat 8.5 though.

I am certain this is a configuration issue on my end, but it has been a bugger.  Over 2 days on this.

It appears when the CAS Spring web application context starts up that it reads the value I have in cas.properties that is in /etc/cas/config.  I put a debug message in org.apereo.cas.util.ResourceUtils on line 97 to print out the location of the JSON registry being loaded.

...
2016-10-06 18:15:25,625 INFO [org.apereo.cas.web.CasWebApplicationServletInitializer] - <The following profiles are active: native>
Resource: URL [file:/etc/cas/services]
...

Then AnnotationConfigEmbeddedWebApplicationContext causes a refresh and the following location is read: classpath:/services

...
2016-10-06 18:15:34,419 WARN [org.apereo.cas.config.CasSecurityContextConfiguration] - <^[[0m>
Resource: class path resource [services]
...
2016-10-06 18:15:34,583 WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceRegistryInitializer' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryInitializer]: Factory method 'serviceRegistryInitializer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedJsonServiceRegistry' defined in class path resource [org/apereo/cas/config/CasCoreServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistryDao]: Factory method 'embeddedJsonServiceRegistry' threw exception; nested exception is java.lang.RuntimeException: java.io.FileNotFoundException: class path resource [services] cannot be resolved to URL because it does not exist>
...

If you have not run into this yet, then you definitely will at some point.  I am trying to get to the bottom of the cause of this.  Any ideas appreciated.

William

unread,
Oct 7, 2016, 11:45:50 AM10/7/16
to CAS Community
I figured out what is causing this.  In cas-server-webapp's src/main/resources/application.properties I had the following:

spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file:/etc/cas/config

In /etc/cas/config/cas.properties I had the following set:

cas.serviceRegistry.config.location=file:///etc/cas/services

This means my service registry is going to be outside the cas-server-webapp in /etc/cas/services.  Since my service registry was outside of cas-server-webapp, I removed cas-server-webapp's src/main/resources/services directory.

I had included cas-server-support-json-service-registry in build.gradle of cas-server-webapp.  On startup this causes org.apereo.cas.config.JsonServiceRegistryConfiguration to read the service registry out of /etc/cas/services.

The stack trace for this call is:

...
        at java.lang.Thread.dumpStack(Thread.java:1329)
        at org.apereo.cas.util.ResourceUtils.prepareClasspathResourceIfNeeded(ResourceUtils.java:101)
        at org.apereo.cas.services.AbstractResourceBasedServiceRegistryDao.<init>(AbstractResourceBasedServiceRegistryDao.java:87)
        at org.apereo.cas.services.JsonServiceRegistryDao.<init>(JsonServiceRegistryDao.java:85)
        at org.apereo.cas.config.JsonServiceRegistryConfiguration.jsonServiceRegistryDao(JsonServiceRegistryConfiguration.java:35)
        at org.apereo.cas.config.JsonServiceRegistryConfiguration$$EnhancerBySpringCGLIB$$20284df4.CGLIB$jsonServiceRegistryDao$0(<generated>)
        at org.apereo.cas.config.JsonServiceRegistryConfiguration$$EnhancerBySpringCGLIB$$20284df4$$FastClassBySpringCGLIB$$39729d3a.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
        at org.apereo.cas.config.JsonServiceRegistryConfiguration$$EnhancerBySpringCGLIB$$20284df4.jsonServiceRegistryDao(<generated>)
...

So far so good.  Then, org.apereo.cas.config.CasCoreServicesConfiguration tries to find the service registry.  Unfortunately, this class does not know that you have a service registry outside of cas-server-webapp and tries to look for it in cas-server-webapp/src/main/resources/services which was deleted.  The stack trace for this call looks like:

...
        at java.lang.Thread.dumpStack(Thread.java:1329)
        at org.apereo.cas.util.ResourceUtils.prepareClasspathResourceIfNeeded(ResourceUtils.java:101)
        at org.apereo.cas.services.AbstractResourceBasedServiceRegistryDao.<init>(AbstractResourceBasedServiceRegistryDao.java:87)
        at org.apereo.cas.config.CasCoreServicesConfiguration$EmbeddedServiceRegistryDao.<init>(CasCoreServicesConfiguration.java:156)
        at org.apereo.cas.config.CasCoreServicesConfiguration.embeddedJsonServiceRegistry(CasCoreServicesConfiguration.java:136)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$b86386ec.CGLIB$embeddedJsonServiceRegistry$8(<generated>)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$b86386ec$$FastClassBySpringCGLIB$$665effef.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
        at org.apereo.cas.config.CasCoreServicesConfiguration$$EnhancerBySpringCGLIB$$b86386ec.embeddedJsonServiceRegistry(<generated>)
...

To fix this just do not delete the services folder out of cas-server-webapp/src/main/resources.

Hope that helps someone.
Reply all
Reply to author
Forward
0 new messages