I am trying to test the spring annotations to get some simple examples (in this case "@ Essential" annotations exclusively).
To begin, I came up with an example of a basic "Hello World" type which does not use any annotation. It prints as expected (i.e. "Hello Spring 3.0 ~!" Print).
Then I added the DAO object field to the Spring3HelloWorld class. My intention was deliberately the reason for creating an exception by interpreting a setter for @ mandatory with DAO , but the exception was not to set it though, Exception is obtained (since this.dao is zero) when I was expecting an exception on the basis of not following the "rules / requirements" annotation.
I thought I need to set the DAO object before calling any method from Spring3HelloWorld , but apparently this is not the case is. I think how I am doing wrong @ mandatory works.
So basically how can I get an error with a line of the following "Hey, you can not do this, you have forgotten to set DAO blah blah."
< P> Spring3HelloWorldTest.java: Import org.springframework.beans.factory.xml.XmlBeanFactory; Import org.springframework.core.io.ClassPathResource; Public square Spring 3 HelloWorld Test {Public Stable Zero Main (String [] Args) {XmlBeanFactory beanFactory = New XmlBeanFactory (New ClassPath Resource ("SpringHelloWorld.xml")); Spring 3 HelloWorld Myben = (Spring 3 Halo World) Bean Factor. Get Bean ("Spring 3 Halo World Been"); MyBean.sayHello (); }} Spring3HelloWorld.java:
import org.springframework.beans.factory.annotation.Required; Public Class Spring 3 Halo World [Private Dao Dao; @ Essential Public Zero Setdoo (DAO Dao) {This Dao = Dao; } Public to say hello () {System.out.println ("Hello Spring 3.0 ~!"); // just public field for testing this area = "Bana !!!"; }} SpringHelloWorld.xml:
Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = " Http://www.w3.org/2001/XMLSchema-instance "xmlns: reference =" http://www.springframework.org/schema/context "xsi: schema location =" http: //www.springframework organization / Schema / Beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/content /spring-context-3.0.xsd"> & Lt; Reference: Annotation-config / & gt; & Lt; Bean square = "org.springframework.beans.factory.annotation.Required Annotation bin Postprocessor" /> & Lt; Bean id = "Dao" class = "SRCDO" & gt; & Lt; / Bean & gt; & Lt; Bean id = "Spring 3 HelloWorldbeans" class = "SRC. Spring 3 Halo World" & gt; & Lt; / Bean & gt; & Lt; / Bean & gt;My first guess is that you will not receive any advanced behavior with spring Comments because you're using
XmlBeanFactoryinstead of the recommendedApplicationContext.- Edit -
Yes - View Stack Overflow
Comments
Post a Comment