In the previous article in this series, we talked about the use of dynamic proxy to complete transaction processing. In this way, all the public methods at the service layer are added to the transaction, this is obviously not what we need. What we need to proxy is the methods that need to operate the database. In this article, we will talk about how to use the Java Annotation (
Identify a class as a Bean using @Repository, @Service, @Controller, and @ComponentSpring has introduced several annotations to simplify the development of spring since version 2.0. @Repository annotations belong to the first batch introduced, which identifies the class of the data Access layer (DAO layer) as a Spring Bean. Just label the note on the DAO class. A
() { bbtForumService.getAllBoard(); System.out.println("call listAllBoard method."); return "listBoard"; } }
From the code above, we can see that there is no difference between Bbtforumcontroller and general class, it does not implement any special interface, so it is an authentic POJO. The magic wand that makes this POJO unique is the annotation of Spring MVC!
Two annotations were used at t
Javax.annotation.PreDestroy;
Import Javax.annotation.Resource;
Import org.springframework.stereotype.Component;
Import com.mth.bean.Student;
Import Com.mth.dao.IStuDao;
@Component ("Stuser") public
class Service {
private Istudao dao;
The method executed before service initialization is equivalent to the Init-method property in the configuration file
@PostConstruct public
void init () {
System.ou
1. identify the class as a Bean using @Repository, @Service, @Controller, and @Component:
Spring has been introduced since version 2.0 to simplify the development of spring. @Repository annotations are among the first to be introduced to identify the classes of the data Access layer (DAO layer) as Spring beans. Simply
("127.0.0.1"); Date now = new Date (); User.setlastvisit (Now.gettime ()); Userservice.handleuserlogin (user);} }Here, we let Testuserservice directly inherit from the abstract test class provided by Spring, and later this article will dissect this abstract test class. All you need to know here is that the purpose of this abstract test class is to let the TestContext test framework run on the JUnit 4.4 test framework.At ①, a class
today I've sorted out the annotations that spring uses:
I hope I can help you!
@ServiceFor labeling business layer components
@ControllerUsed to label the control layer component (such as action in struts)
@RepositoryUsed to annotate a data access component, the DAO component
@ComponentAs a component, we can use this annotation to annotate when the component is not properly categorized.
@AutowiredThe ge
that the agreement is better than the configuration.
Solution:
The transformation process is to first add the @ repository tag to the DAO implementation class, which indicates that this is a service of the persistent layer. The two-layer tag @ service and @ controller are implemented as follows:
import org.springframework.stereotype.Repository;...@Repositorypublic class ScDbInfoDAOImpl extends SqlMapClien
Spring annotation Component
In the previous article, we described dependency injection annotations in detail, especially @ Autowired. However, our bean definition declaration is still placed in the xml configuration file. Of course, Spring provides a mechanism to automatically scan class paths and automatically register BeanDefinition with the container. This is
Spring Timer technology Terminator -- Implement Spring timer using Scheduled Annotation
There are two ways to implement the timer function in Spring: Scheduled annotation mode and XML configuration mode, this blog introduces how to use Scheduled
org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;@Servicepublic class PersonService {@Autowiredprivate PersonDao personDao;public Person getPerson(int id) {return personDao.selectPersonById(id);}}The @ Service annotation is used in the Service class, And the @ Autowired ann
Spring study notes -- about the problem that Spring annotation scan cannot inject new objects
Over the past few days, Leader has made me use the factory model to refactor some of the business logic code. The process is painful (I will not elaborate on it here) and the results are very sweet. Below is a record of a problem I encountered during the refactoring proc
annotation will be rolled back to assemble by type. However, once the name attribute is specified, it can only be assembled by name.
Beans. xml
Persondao. Java
packagecn.itcast.dao;publicinterfacePersonDao{publicvoidadd();}
Persondaobean. Java
Package CN. itcast. dao. impl; import CN. itcast. dao. persondao; public class persondaobean implements persondao {public void add () {system. out. println ("the add () method in the persondaobean is executed
anything, and it only provides metadata information. To make the metadata really take effect, the processor responsible for processing the metadata must work.Autowiredannotationbeanpostprocessor and commonannotationbeanpostprocessor are the processors that process the annotation metadata. However, defining these beans in the spring configuration file is clumsy. Spring
This article from: http://blog.csdn.net/dqatsh/article/details/3478000
I found a good article http://www.ibm.com/developerworks/cn/java/j-lo-spring25-ioc/ which gives a more detailed description than this article.Springframework 2.5 introduces a complete annotaion configuration annotation. Using these annotation can greatly reduce bean definitions and make Program Development easier and easier to maintain.O
@Controller @Service @Controller and @ComponentRegistering an action into the spring context, the Bean's ID defaults to the first letter of the class name lowercase.@Repository, @Service and @controller. These 3 annotations and @Component are equivalent, but from the name of the annotation class it is easy to see that
Can spring annotations perceive each other ?, Spring annotation awareness
Currently, spring mvc is used to write a remote control tool. Today I wrote two classes of dao layer, and then extracted a dao layer interface. When exporting the interface, the annotation @ Transacti
I. Development of annotations
import jar package; Spring-aop-xxx.jar
Import constraint: (available in Official document Xsd-configuration.html) beans xmlns = "Http://www.springframework.org/schema/beans" Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance" Xmlns:context = "Http://www.springframework.org/schema/context" xsi:schemalocation = "Http://www.springframework.org/schema/beans http://www.springframework.org/ Sche
Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.Service; @Servicepublic class Personservice {@Autowiredprivate Persondao Persondao; Public person Getperson (int id) {return Persondao.selectpersonbyid (ID);}}The @service annotation adornment is used on the service class and has a @autowired
Talking about the annotation methods of AOP in spring and AOP in spring, springaop
AOP (Aspect Oriented Programming): the terminology of AOP is "Aspect-Oriented Programming". What is Aspect-Oriented Programming? I understand that it enhances functionality without modifying the source code. well, we will mention this in the context of the aop
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.