Could not autowire.

87 views
Skip to first unread message

Thomas Tong

unread,
Jan 22, 2023, 12:31:57 AM1/22/23
to CAS Community
Hi, everyone
      I'm new developer to CAS. I downloaded CAS7.0.0.RC3 with CAS Initliazr to test. I defined a AutowiredTestService.java as below.
 
package org.apereo.cas.config;
import org.springframework.stereotype.Service;

@Service
public class AutowiredTestService {
    public AutowiredTestService(){
        System.out.println("AutowiredTestService is constructed....");
    }
}

But Idea reports "Could not autowire" when I tried to Autowired this service in Autowired annotation.

package org.apereo.cas.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;

@AutoConfiguration
//@EnableConfigurationProperties(CasConfigurationProperties.class)
public class CasOverlayOverrideConfiguration {
    @Autowired
    public AutowiredTestService autowiredTestService;

}

And after I tried to run CAS in tomcat, following error is reported out. 
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apereo.cas.config.CasOverlayOverrideConfiguration': Unsatisfied dependency expressed through field 'autowiredTestService': No qualifying bean of type 'org.apereo.cas.config.AutowiredTestService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Would you like to let me know how to fix it? Thank you very much.

Ray Bon

unread,
Jan 23, 2023, 12:18:54 PM1/23/23
to cas-...@apereo.org
Thomas,

What is it that you are trying to do?

The capability may already exist.

If the problem is related to test classes, you may have to import packages. For example, I have:

testCompileOnly "org.apereo.cas:cas-server-core-webflow-api"
testImplementation "org.apereo.cas:cas-server-core-services-authentication"

The war file pulled in with war-overlay does not include test artifacts.

Ray

On Sat, 2023-01-21 at 18:58 -0800, Thomas Tong wrote:
Notice: This message was sent from outside the University of Victoria email system. Please be cautious with links and sensitive information.

Thomas Tong

unread,
Jan 29, 2023, 1:41:34 AM1/29/23
to CAS Community, Ray Bon
Thanks Ray's response very much. Finally, I got this to work after I added AutowiredTestService to org.springframework.boot.autoconfigure.AutoConfiguration.imports.

Char Lin

unread,
Jun 19, 2023, 6:38:33 AM6/19/23
to CAS Community, thms...@gmail.com, Ray Bon
Hi, all.
If I have many beans that annotated by @Service,@Component...  do I need to add them one by one to org. springframework. boot. autoconfigure. AutoConfiguration. imports?
Is there any way for Spring to scan my package‘s path, and Inject them into the IOC container? Thanks.
Reply all
Reply to author
Forward
0 new messages