Discover spring bean configuration xml file, include the articles, news, trends, analysis and practical advice about spring bean configuration xml file on alibabacloud.com
There are three places for DAO, service, and servletGenerates an object by matching the file XML and injects properties of the object type, reducing the couplingDAO file Code: Package Com.swift; Public class Daouser { publicvoid Fun () { System.out.println ("I ' m Dao's Fun () ...................."); }}Service
1. Use XmlBeanFactory to read the spring configuration file:
Resource resource=new ClassPathResource("conf/spring/applicationContext.xml"); BeanFactory factory=new XmlBeanFactory(resource); com.geostar.query.beans.DataSource ds=(com.geostar.query.beans.DataSource)factory.getBean("ds");System.out.println(ds.getDriver
First, the bean initialization and destructionIn our actual development, we often encounter beans before or after the use of the necessary operations, spring on the Bean's life-cycle operations to provide support. There are two ways to use Java Configuration and annotation configurations:(1) How Java is configured: Use the Initmethod and Destroymethod of the @
In order to reduce the configuration in XML in spring, you can create a configuration class (for example, exampleconfiguration) to configure the bean.1. Configure the spring configuration
Summary IOC DI Overview • Configure the bean– configuration form: XML file-based approach, annotation-based –bean configuration: Through the full class name (reflection), through the factory method (static factory method Instanc
Background: The database information is generally configured in the Db.properties file, but the properties file parsing is a troublesome thing
The STRUTS2 Integrated Spring Framework provides a way to parse the properties file, in the following steps:
1. Make the following configu
;} The class identified by the @configuration annotation, typically as a configuration class, is similar to an XML file, which indicates that bean metadata is configured in that class, which acts like a application-context.xml c
"Bean Configuration"To configure a bean in an XML file through a bean node1 2 Configuration Bean3 the full class name of the Class:bean, which creates the
-based configuration of beans (based on annotation configuration beans; Assembly of bean attributes based on annotations) scan components in Classpath• Component scanning (component scanning): Spring is able to automatically scan, detect and instantiate components with specific annotations from the classpath.• Specific
{
@Autowired
@Qualifier ("Testhibernatedao")
Private Testhibernatedaoimpl DAO;
Public Testhibernatedaoimpl Getdao () {
return dao;
}
}
2, spring configuration file using Chapter12/componentdefinitionwithannotation.xml can and without modification;
3. Define test methods:
Java code: Java code @Test public void Testservice () {Tests
First, Bean naming1. Direct naming1.1, directly using the spring default naming method, do not specify id;1.2, only the fully qualified class name must be configured by the IOC container for it to generate an identity, 1.3, the client must pass the interface "T Getbean (classclass= "Wang.conge.HelloImpl"/>= Application.getbean (Helloimpl. Class);2. ID NameEach bean
modules that the IOC brings to us and the ease of application.So why is the IOC simple? In fact, it is by our usual new turn to use reflection to get the instance of the class, it is believed that anyone will use the Java reflection mechanism, it is not impossible to write an IOC framework. Like what:......Public Object getinstance (String className) throws Exception{Object obj = Class.forName (className). newinstance ();Method[] methods = Obj.getclass (). GetMethods ();for (Method method:metho
reflection to get the instance of the class, it is believed that anyone will use the Java reflection mechanism, it is not impossible to write an IOC framework. Like what:......Public Object getinstance (String className) throws Exception{Object obj = Class.forName (className). newinstance ();Method[] methods = Obj.getclass (). GetMethods ();for (Method method:methods) {if (Method.getname (). Intern () = = "SetString") {Method.invoke (obj, "Hello world!");}}}......One of the methods above is to
Org.springframework.context.annotation.AnnotationConfigApplicationContext;
Import SpringStudy.Model.Counter;
Public class Springtest {
public static void Main (string[] args) {
//applicationcontext ctx = new Classpathxmlapplicationcontext ("Spring/bean.xml");//Read the contents of Bean.xml
ApplicationContext annotationcontext = new Annotationconfigapplicationcontext ("Springstudy");
Counter C = Annotationcontext.getbean ("Counter",
want to use Factorybean to create a bean instance, you need to inherit the Abstractfactorybean abstract class, and the CreateInstance () method to create the target bean instance, In order for other beans to autowire the bean, it is necessary to implement the Getobjecttype () method to return the type of the target bean
Label: style blog color Io use Java file SP Div
In the XML file,First, let's look at the following code:
Color enhancement section. When we used to depend on other beans for Bean, we needed to specify the bean for container initialization and loading, but is there a way to
@Configuration equivalent to beans, @bean equivalent to beans.The following is a typical spring configuration file (application-config.xml):Then you can use a bean like this:ApplicationContext CTX = new Classpathxmlapplicationcont
This causes a circular reference to initialize the bean problem. It seems that the XML configuration still has advantages//03-11 17:01:50.010 main WARN O.s.b.f.s.defaultlistablebeanfactory-bean creation//EXC Eption on Factorybean type check://Org.springframework.beans.factory.BeanCreationException:Error Creating
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.