The configuration file differs greatly from the way annotations are, with many more configuration items.
Beans2.xml
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context"xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xsi:schemalocation= "Http://www.springframework.org/schema/beansHttp://www.springframework.org/schema/beans/spring-be
The role of the spring framework: To simplify Java developmentSpring is an open source framework, and spring is a lightweight Java development framework that emerged in 2003 by Rod Johnson in his book expert one-on-one development and Some of the concepts and prototypes elaborated in design are derived. It is created to address the complexities of enterprise application developmentI. IOC (Control reversal)1
Packagecom.baobaotao.conf;importorg.springframework.beans.factory.annotation.autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.configuration;import org.springframework.context.annotation.importresource;// Introduction of XML configuration file @configuration@importresource ("Classpath:com/baobaotao/conf/bean2.xml") via @importresourcce public clas
Maven+mybatis+spring encountered the following error while developing:Org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating Bean with Name ' Xxxservice ': Unsatisfied dependency expressed through field ' Xxxmapper '; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' Xxxmapper ' defined in file [Xxxmapper.class]: Cannot resolve reference to beans ' sqlsessionfactory '
I. Overview.
The previous blog describes the implementation of AOP using XML to implement AOP in the form of annotations, which now describes another AOP implementation.
Second, the code demonstration.
Preparation work Reference Previous blog "Rookie learning spring--60s using annotation to implement simple AOP"
Directory structure:
1, the introduction of Spring.jar package.
2, write code
Description: These classes and XML configuration files are in the same package "Springtest"
Interface Class Tinterface.java
Public interface Tinterface {Public String getName ();}
Interface Implementation Class Timpl.java
public class Timpl implements tinterface{
Public String GetName () {Return ' This is Spring test ';}
}
IOC Invoke Class Tservice.
declares a property in the
If the injected value has a special character Furu "
The console prints a value of
(1) When injecting a property into a bean, if it contains other beans, you can specify a reference to the bean by the element or ref property for the Bean's property or constructor parameter.(2) A bean's declaration can also be included in a property or constructor, which is called an internal bean and can be declared as an internal bean when the bean instance is used only
Classpathxmlapplicationcontext ("Classpath: Applicationcontext.xml "); Declareservice HS = Ctx.getbean ("Showservice", declareservice.class); System.out.println ("======================================"); Hs.declare (); System.out.println ("======================================");}We get or showservice bean, run the next test method output result:======================================declare=========================================================== Copyright NOTICE: This article f
First, create a spring projectProject Name: spring101501Ii. adding spring support to the project1. Create a Lib directory in your project/lib2. Add the jar package in the Lib directoryCom.springsource.com.mchange.v2.c3p0-0.9.1.2.jarCom.springsource.org.aopalliance-1.0.0.jarCom.springsource.org.aspectj.weaver-1.6.8.release.jarCommons-logging.jarJunit-4.10.jarLog4j.jarMysql-connector-java-5.1.18-bin.jarSpring
The structure of the XML file is generally as followsxmlns is an abbreviation for XML Namespace, which represents the spring namespace. Spring finds all the spring.handlers in Classpath and parses the XML configuration namespace with the corresponding processing class. These
Web. xml files generally include servlet, spring, filter, and listenr configuration.Loading Order will affect spring bean calls.Listener> filter> servlet> springIf bean is used in the filter, you can change spring loading to listener.
Org. springframework. Web. Context. contextloaderlistener
Their internal ex
Xml for spring Injection
1. Inject xml into xml for configuration
Note: The spring container is executing code
ApplicationContext ctx = new ClassPathXmlApplicationContext (beans. xml );
Key Note: bean name is unique and describe
/context/spring-context.xsd " >Iv. Creating a business bean1. Create a business bean package in the SRC directoryPackage Name: Cn.jbit.spring101003.service2. Create a business bean under a packageBusiness Bean Name: Userservice.javaBusiness Bean Content:/*** By proxy class* @author Administrator**/public class UserService {/*** 3. Delete*/public void Delete () {System.out.println ("Delete method");}}Five. Creating slices1) Create the package under SRC
Spring Declarative Transaction Management
Spring's declarative transaction management is implemented through spring AOP, and Spring provides a declarative rollback rule: We can specify what exceptions will result in a rollback. XML version Configuration
Some of the methods configured for the service layer include tr
Unable to locate spring namespacehandler for XML Schema namespace [http://www.springframework.org/schema/aop]
I don't know if you have ever encountered this problem. Today, when I used myeclipse to build a spring project, this problem has always occurred. I had to think about it before and finally discovered it, because I am too dependent on the plug-in, myecl
Reprinted blog: http://blog.163.com/zhangke_616/blog/static/191980492007994948206/In the actual project spring's configuration file Applicationcontext.xml is loaded through spring provided by the loading mechanism, automatically loaded in the container, in the Web project, the configuration file is loaded into the Web container for parsing, currently, Spring provides two loaders for the Web container to loa
How the Spring Framework's XML file reads the properties file dataFirst step: In the Spring configuration fileNote: Value can be configured with more than a few properties files class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > Step Two:Build the Db.properties file under the src directoryUser=saPassword=saDriver=c
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.