For Spring annotation @ Service @ Component @ Controller @ Repository usage, @ service @ component
@ Component is equivalent to the object of the instantiation class. The other three annotations can be understood as the subannotation or refinement of @ Component.
In the annotaion configuration
Add a post. Continue to talk about how your annotation is handled.
The main purpose is to add an RPC layer, which provides the service layer and Protocol Resolution layer for transparent RPC calls.
For the service layer, the business logic is concerned. With the Spring AOP principle, the
Scenario:
When using spring mvc, I used an annotation such as @ Service and found that the transaction declared by @ Transactional does not work.
My configuration is as follows:
The reason is::
The context of component-scan is different from that of the transaction. The configuration of component-scan is loaded by servlet, And the configuration file of the tra
In addition to providing @ component annotations, spring 2.5 also defines several annotations with special semantics: @ repository, @ service, and @ controller. In the current spring version, the three annotations are equivalent to @ component, but from the annotation class name, it is easy to see that the three annota
Reprint: http://blog.csdn.net/xwnxwn/article/details/52679578Ways to get Webapplicationcontext: http://panyongzheng.iteye.com/admin/blogs/1477702XML is scanned in sequence reference: http://sence-qi.iteye.com/blog/1328902The bean that @controller annotations can be successfully scanned in the following way, not the bean that the @service/@Repository is scanned. That's rightJava code
package="Org.bdp.system.test.controller" >
"
= ' name ', column = ' name '), @Result (property = ' age ', column = ' Age ')}) @Select (" Select name, age from User ") listIn the preceding code, the property attribute in the @Result corresponds to the member name in the user object, and column corresponds to the field name of the Select. The id attribute is intentionally not detected in this configuration, only the name and age objects in the user counterpart are mapped, so that the ID identified is null by the following unit test, and
Spring5: @ Autowired annotation, @ Resource annotation, and @ Service annotation, spring5 @ resource
What is annotation?
The traditional Spring method is to use the. xml file to inject beans or configure aop and things. This metho
can be said to be a manifestation of the state pattern in the design pattern and also an Application Part of polymorphism in object-oriented programming.
In the Spring framework, when we use condition annotations, we create a class for each independent condition, depending on the conditions corresponding to this class, we can select different tasks for execution. Of course, we generally use interfaces to declare a task. Because we will specify the sp
: schemaLocation = "http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd>
2. Use Spring annotations to define beansThe above section describes how to implement automatic injection in Bea
Java -- Spring annotation and spring Annotation
Common Spring annotationsConstruct an IoC Container Using annotationsUse annotations to register beans with Spring containers. You must register For example, specify a package in bas
instantiating a DemoService, another class uses generic injection List. Spring successfully puts the instantiated object into the List. After the idea is opened, we can better talk about Map. Spring uses the service name as the key, and the object is encapsulated into the Map as the value.
The sample code is as follows:
DemoService code:
Package com. secbro. lea
Spring annotation accumulation and Spring annotation Accumulation
Use annotations to register beans with Spring containers.
Register in applicationContext. xml:
1
For example, specify a package in base-package.
You can also specify multiple packages in
============
1: @
{
@MethodInfo (name= "Java", value= " Spring Framework is important ") public
void Java () {
}
}
3. Write test class Annotationtest, resolve the above two annotation attributes
Package com.itheima10.annotation;
Import Java.lang.reflect.Method;
Import Org.junit.Test;
public class Annotationtest {
the public static void Test () {
/**
*
userService.In the future, we can use getBean ("userService. If we do not specify userService, the key of the bean to be stored in the container is userServiceImpl by default, so that we can get a container containing the UserServiceImpl object.Package com. spring. service;Import org. springframework. stereotype. Component;Import com. spring. dao. UserDao;@ Comp
Simulate and implement annotation Assembly in Spring, spring Annotation
Original article, address for http://www.cnblogs.com/fengzheng/p/5037359.html
In Spring, bean configuration in the XML file is the core configuration file for implementing
@ Service annotation, @ Service Annotation
First, add a line in the applicationContext. xml file:
After this line is added, the package under the path will be automatically scanned. If a class carries the @ Service annotation,
Spring annotation and spring Annotation
Component Annotation
@ Controller: used to mark control layer components (control layer)
@ Service: used to mark Service layer components (
Spring annotation configuration startup process, spring annotation process
Recently I saw the spring source code and suddenly wanted to know how spring started itself through a class inherited from AbstractAnnotationConfigDispatch
In the process of using Spring, in order to avoid using a large number of Xml configuration files injected by Bean, we will use the automatic scan injection method provided by Spring, just add several lines of automatic injection configuration, you can complete
Service layer, Controller layer, and so on. during use, add @ Compopnet
Spring annotation configuration Transaction Management-problems, spring annotation configuration transactions
Configure in the context:
Note:
1. If the configuration is complete, an error is returned --
java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getConnectionProvider()....Soluti
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.