• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

InaccessibleObjectException

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typically, we use @Configuration class to define beans


Reference:
https://www.baeldung.com/spring-bean
https://medium.com/javarevisited/spring-beans-in-depth-a6d8b31db8a1
https://www.geeksforgeeks.org/spring-bean-annotation-with-example/


 
reply
    Bookmark Topic Watch Topic
  • New Topic