Spring -servlet.xml beans access -
in spring access bean using method getbean(). eg:
the aplicationcontext.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www... etc"> <bean id="myclass" class="ioc.beans.myclass" /> </beans>
the java:
applicationcontext applicationcontext = new classpathxmlapplicationcontext("applicationcontext.xml"); myclass cl = applicationcontext.getbean("myclass", myclass.class);
now i'm working spring mvc , beans created in xml file suffix -servlet, , don't have classpathxmlapplicationcontext.
how can access java beans controller work objects, if not have getbeans method? (considering method -the first , foremost feature of spring @ initiation tutorial- bad practice).
if you're using spring within web application there's no real reason programmatically beans that.
you should use either explicit constructor/setter injection or autowiring. in first case, spring-managed beans should defined in xml (or javaconfig if you're using it). in second, classes autowired should either declared in xml/javaconfig or should on component scan path.
Comments
Post a Comment