This isn't really a CAS issue, but rather understanding how Spring
configuration works.

Create a Spring configuration class with the following annotations
adjusting accordingly to your environment.

package some.package;
@Configuration
@ComponentScan(basePackages =
{"some.package.you.want.scanned","some.other.package.you.want.scanned"})
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class YourSpringConfigurationClass  {
@Autowired
private CasConfigurationProperties casProperties;
.
.
//you can choose to create beans here as well.
.
}

In your MyAuthenticationHandler class,  add  the annotation @Component to
it.  This will allow the @ComponentScan annotation to find your bean, and
create it.

In the jar file where your class lives,
add a folder META-INF, and a spring.factories file in it.
It typically would live in at src/main/resources/META-INF/spring.factories
inside your source directory.

In the spring.factories file, add the line
org.springframework.boot.autoconfigure.EnableAutoConfiguration=some.package.YourSpringConfigurationClass,
some.package.AnotherSpringConfigurationClassIfNeeded

This tells Spring where to find your Spring configuration class.



*References*:
https://dzone.com/articles/apereo-cas-step-by-step-guide-to-implement-a-custom-authentication-handler
https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/boot-features-developing-auto-configuration.html
https://www.baeldung.com/spring-component-scanning



On Mon, Jun 19, 2023 at 5:38 AM 'Char Lin' via CAS Community <
cas-user@apereo.org> wrote:

> Hi, all.
> Just like the title, CAS 7.0.0, I can't atowired the bean annotated by
> @Service and @Component... How to configure scan them and add to spring
> bean factories?
>
> [image: 20230619181953.png]
> From the picture, I started the cas application, but report the
> 'userService is null'
> who can help me, thank you very much!
>
> --
> - 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/68985f35-fdd1-4077-8f06-612ea0331959n%40apereo.org
> <https://groups.google.com/a/apereo.org/d/msgid/cas-user/68985f35-fdd1-4077-8f06-612ea0331959n%40apereo.org?utm_medium=email&utm_source=footer>
> .
>

-- 
- 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/CAL3JkELj5UAfXjw%3DpwpzcidpcOJZQ32io0H146-3XhvaP%3DErXw%40mail.gmail.com.

Reply via email to