I have a non-public bean class in the package "demo.beans" with some setter methods.
I am setting these values in the Spring configuration file. But, setter injection should be failed since my bean class is in different package and BeanFactory (or XmlBeanFactory) is in different package.
Spring Client Application:
Configuration file:
But, it is running normally. How BeanFactory was able to access my bean class ( with default access ), which is in the other package? How JVM allows this?
In the config file(demo.xml), you will be writing the bean with the fully qualified class path. From there withe default access specifier bean is getting instantiated and you are able to run your spring application successfully.
Even if it knows that my bean class is there.... it shouldn't access my class because both are in different packages.
According to java rules, only public classes can be accessed from other packages. For this reason only we will specify the class which has main() method (it should be invoked by JVM) as public. Right?
I got following answer from Java_Official Yahoo Group.
I think this is because Spring use reflection to initiate your bean and invoke its method. So even the bean class itself is not visible for the bean factory it still can access it.
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, the permaculture playing cards