Hi all
New to Spring. Using Spring 4.2.4. And learning Annotations. Created 3 classes in the same package for ComponentScan annotation use.
---------------------------------------------------------------------------------------------------------
package com.SriluPractice.CollegePackage;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = "com.SriluPractice.CollegePackage")
public class CollegeConfig {
}
----------------------------------------------------------------------------------------------------
package com.SriluPractice.CollegePackage;
import org.springframework.stereotype.Component;
@Component("collegeBean")
public class College {
}
-------------------------------------------------------------
package com.SriluPractice.CollegePackage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Client {
public static void main(
String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(CollegeConfig.class);
College college = context.getBean("collegeBean", College.class);
System.out.println("Collage Object is created by Spring is : " + college);
}
}
---------------------------------------------------------------------------------------------------------
When I run Client.java, I get Exception in
thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.SriluPractice.CollegePackage.CollegeConfig
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:410)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @3901d134
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)