Discover spring bean configuration xml file, include the articles, news, trends, analysis and practical advice about spring bean configuration xml file on alibabacloud.com
Tag: Amp XML File Port string Word GRE file ring methodHow beans are configured: Through the full class name (reflection), through the factory method (static factory method Instance Factory method), FactorybeanThis is where the bean is configured based on the full class nameDependency Injection Mode:Attribute injectio
One, two ways to configure beans using the XML configuration Bean1. Introduction of external Properties file in IOC containerIn an IOC container, when a bean is configured, it is sometimes necessary to introduce information about the system deployment in the bean's configuration
Org.springframework.stereotype.Service;
@Service ("UserService")//labeled as Bean public
class Userserviceimpl implements UserService {
@Resource (name= " Userdao ")//Assemble the private Userdao Userdao by the name of the Bean
;
public void Setuserdao (Userdao userdao) {
This.userdao=userdao;
}
@Override public
Void Save () {
//TODO auto-generated method Stub
this.userDao.save
I. knowledge points
In spring, propertyplaceholderconfigurer is the Bean Factory post-processor used to separately put some bean configurations into an attribute file. Variables in the form of $ {var} can be used in the bean configuratio
The bean in the Pring configuration directly references the attribute values of other beans to assign values to the attributes of the current bean. You can also directly call other bean methods to obtain the returned values and assign values to the attributes of the current bean
little mysterious.First, add a static method for bookfactory:Package Model. factory; Configure book Bean:This bean gets the book object instead of bookfactory.
Automatic Assembly:That is, the attributes of a bean can be matched by the container itself, and autowire can be automatically assembled to get "bytype" or "byname ";
Annotation injection: After 3.0, you can enable annotation so that the container c
Add Lazy-init property to a bean: Lazy-init setting only works on beans with SCOP property singleton1 XML version= "1.0" encoding= "UTF-8"?>2 Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 Xmlns:context= "Http://www.springframework.org/schema/context"5 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframewo
The problem is this.Development environment: Win7 + tomcat7 + jdk1.7 + spring4.5
I used XML to configure some of the parameter information to use when Bean,tomcat started, I modified the parameter information in the XML file and then reloaded the bean with the following met
Scope describes how the spring container creates a new instance of the bean, implemented by @scope annotations:
The spring container initially provided the scope type of two beans: Singleton and prototype, but after release 2.0, another three scope types were introduced: request, session, and global session. These three types can only be used in Web applications
In addition to writing a very simple loading of an XML, loading a number of cases has been useless, in the company will not be handled by themselves this problem, now need to use, research and verification.The case used is also the example above.Only, divide the original beans.xml into two parts. 1. Structure 2.beans.xml1 XML version= "1.0" encoding= "UTF-8"?>2 Beansxmlns= "Http://www.springframework.org/
attribute-Pass method parameters for factory methods using the Constructor-arg elementStatic Factory class: 1 package com.yl.factory; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6/** 7 * Static Factory method: A static method that calls a class directly can be associated with an instance of the returned Bean 8 * @a Uthor Yul 9 *10 */11 public class Staticcarfactory {$ private static mapInstance Factory class:1 package com.yl.fa
namespace, you need to import the context namespace: 3 Configure the external file in the configuration file, and the bean instance of C3P0, with the following code:XML version= "1.0" encoding= "UTF-8"?>Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xm
) Applicationcontext.getbean ("UserService"); User User1 = (user) Applicationcontext.getbean ("User"); User User2 = (user) Applicationcontext.getbean ("user"); User1.setname ("xiaoming"); User1.setsex ("male"); User1.setage (22); User2.setname ("Little Red"), User2.setsex ("female"), User2.setage (), Service.add (user1); Service.add (User2);}}Results:when a specific annotation is used in a component class, the :
The Base-package property specifies a base class package that needs to be
billing serviceRelated beans and it depends onBaseservices.xml,which providesService Bean Templates ......
One advantage of using the description tag is that it is easy to use tools to select and remove description from the tag.
10. For any change, to actively communicate with teammates
When you refactor Java code, you need to update the configuration file and
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.