method will not show the configured transaction settings.4. @Transactional annotations can be applied to interface definitions and interface methods, class definitions, and public methods of classes. Note, however, that only @Transactional annotations appear to be less than the open transaction behavior, which is only a meta-data that can be used to identify @Transactional annotations and the beans that are configured appropriately to have transactional behavior. In the above example, it is act
1, In a host-based configuration spring configuration file, you may see a configuration like spring container autowiredannotationbeanpostprocessor,commonannotationbeanpostprocessor, Persistenceannotationbeanpostprocessor and requiredannotationbeanpostprocessor the 4 beanpostprocessor. Registering these 4 beanpostprocessor functions is for your system to be able to identify the corresponding annotation
Spring MVC annotation development and use details, mvc use Details
MVC annotation-based development is annotation-based class development for processors. For each defined processor, you do not need to register it in xml.
You only need to annotate classes and methods in the code to complete registration.
Define Processo
classes) rather than on any interface that the class implements. You can certainly use @Transactional annotations on the interface, but this will only take effect if you set up an interface-based proxy. Because annotations are not inherited, this means that if you are using a class-based proxy, the transaction's settings will not be recognized by the class-based proxy, and the object will not be wrapped by the transaction proxy (it will be identified as critical). Therefore, accept the suggesti
ModelAndView();mv.addObject("message", "Hello World!!!");mv.setViewName("/view/hello");return mv;}}
In the body of Hello. jsp, the following content is written:
The directory structure of this project is as follows:
Enter http: // localhost: 8080/springmvc/user/getuser. Do to view the result.
Note:
If you want to use the @ autowired annotation, you must declare the autowiredannotationbeanpostprocessor bean in the
example, it is actually the presence of the 5. The spring team's recommendation is that you use @Transactional annotations on specific classes (or methods of classes) rather than on any interface that the class implements. You can certainly use @Transactional annotations on the interface, but this will only take effect if you set up an interface-based proxy. Because annotations are not inherited, this means that if you are using a class-based proxy,
1. Enable support for @aspectj
In addition to supporting schema configuration for AOP, spring supports annotation methods: using @aspectj-style facet declarations.
Spring does not support @aspectj-style facet declarations by default, in order to support the need to use the following configuration:
This allows spring t
://image.uc.cn//s/wemedia/s/upload/2017/ Adfb48f81f7601d4748786cd457d61fcx960x487x89.png "alt=" adfb48f81f7601d4748786cd457d61fcx960x487 "/>650) this.width=650; "src=" Http://mp.sohu.com//editor/themes/default/images/spacer.gif "alt=" Spacer.gif "/> Next, Let's take a look at how to deal with annotations, such as:650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 0dda31d1667ccdf33fc5149c8863b319x895x711x29.png "alt=" 0dda31d1667ccdf33fc5149c8863b319x895x711 "/>This section
Annotation management is much simpler than the way XML is configuredSimply add the transaction annotations in the configuration file1 XML version= "1.0" encoding= "UTF-8"?>2 Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:tx= "Http://www.springframework.org/schema/tx"4 XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5 Xmlns:context= "Http://www.springframework.org/schema/context"6 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-ins
SPRING-MVC Object Encapsulation JSON returns when deleting attributes in Object annotation method In the class name, followed by verbal annotations used in@JsonIgnoreProperties (value={"Comid"})//properties that you want to dynamically filter outCases@JsonIgnoreProperties (value={"Comid"})Public interface Interface Name {}@JsonIgnoreProperties (value={"Comid"})public class class Name {}This
, an exception thrown at a non-runtime, the compiler will check for an exception to be checked or a check exception), we specify the way to let the transaction roll back, as follows:@Transactional (Rollbackfor=exception.class)//Specify Rollback, rollback when an exception Exception is encounteredpublic void MethodName () {throw new Exception ("note");}@Transactional (Norollbackfor=exception.class)//Specifies no rollback and encounters a run-time exception (the throw new RuntimeException ("note")
Spring Mvc execution principle and xml annotation configuration (6)Spring MVC execution principle in Spring Mvc access process, each request first goes through many filters and is processed by DispatcherServlet; in a Spring MVC project, multiple dispatcherservlets can be con
Configure in Context:Note:1. If the configuration completes the error--Java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getConnectionProvider () ....Solutions--You ' re using Spring 3.2.5, and it's not a compatible with the latest Hibernate 4.3.3 version, which you ' re using. Hibernate 4.3 indeed decided to change theConnectionProviderreturned bySessionFactoryImplementor.getConnectionProvider(). Use the latest
Transferred from http://www.cnblogs.com/leiOOlei/p/3713989.html
Spring opens annotation
The difference between
are used to activate the beans that have been registered in the Spring container, either through XML or through package sanning.
Let's look at their differences in detail by example, with three class a,b,c and B,c objects injected into A.
Package
Transaction management under Spring-using AOP @Transactional annotation Management
In addition to using XML configuration management, AOP has a way of transaction management: Using @Transactional annotation transaction management.The class definition includes:
When the above-mentioned POJO is defined in a Spring IoC
difficulty.Advantages and disadvantages of annotation configuration:The advantages are:1. In the class file, the maintenance cost can be reduced, the annotation configuration mechanism is obviously simple2. No third-party parsing tools are required, and Java reflection technology is used to complete the task3. Editing period can verify correctness, error becomes easy4. Improve development efficiencyDisadva
test difficulty.
Advantages and disadvantages of annotation configuration:
Advantages:
In the class file, maintenance costs can be reduced, and the annotation configuration mechanism is clearly simple
No third-party parsing tools are required, and Java reflection technology is used to accomplish tasks
Edit period can verify correctness, error becomes easy
Improve development effic
annotation interceptor is implemented to add an annotation to the required interception method @accessrequiredExamples of usages in the Spring MVC controller?
123456789
/***注解拦截器方法*@return*/@RequestMapping(value="/urlinter",method=RequestMethod.GET)@AccessRequiredpublic @ResponseBodyStringurlInterceptorTest(){return"通过拦截器:user"+request.getAttrib
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.