of the AOP, the more executed first. (Chain mode),So we need to add the Order property to/> in 。 This is a transaction nesting.So let's look at the example above: When a Class (Test) is using @transactional in a Oddtech.service.impl package, we want the Insert method to be read-only, Read-only=true, So we need to define this: @Transactional (readOnly = true,propagation=propagation.required), why?In a declarative transaction, our transaction propagation level for insert is defined as: REQUIRED,
Spring opens annotation The difference between are used to activate beans that have already been registered in the Spring container, either through XML or through the package sanning.Let's take a look at their differences in detail below, with three class a,b,c, and the B,c object is injected into A.Package Com.xxx;public Class B {public B () { System.out.pri
[] args) {ApplicationContext ctx=NewClasspathxmlapplicationcontext ("Bean.xml"); Performer Performer= (performer) Ctx.getbean ("Xingoo"); Performer.perform (); }}The following are the key configuration filesThe configuration file at this point is aware that spring will know which one is the normal bean and which is the notification. It is therefore necessary to add an attribute to ensure that AOP automatically recognizes notifications.Class="true"/
, there is no ambiguity and it is recommended.
2. Automatic assembly according to type (Bytype). The spring container may find multiple beans of the same type as the bean that needs to be injected, so there is ambiguity, and the spring container does not know which bean to inject, and throws an exception.
3. Automatic assembly according to the constructor (constructor). This approach is more complex and doe
spring2.5 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
@Resource By default is assembled by name, only if the bean that matches the name is not found to assemb
Description and Difference
spring4.1 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
A. @Resource By default is assembled by name, only if the bean that matches the n
annotation interceptor is implemented to add an annotation to the required interception method @accessrequired Examples of usages in the Spring MVC controller /** * Annotation Blocker method * @return */@RequestMapping (value= "/urlinter", Method=requestmethod.get) @AccessRequiredpublic @ Responsebody String urlinterc
Spring AOP is based on the annotated "0 configuration" approach:In the beans.xml of springIn the main method of Beantest // 1. Create a spring IOC container New Classpathxmlapplicationcontext ("Beans.xml"); ///2, get bean Hello hello = Ctx.getbean ("Hello", hello.) from the IOC container. Class); //3, method of calling Bean hello.foo (); Hello.adduser ("Monkey King", "7788");Use the @aspect to declare
Transferred from: http://snowolf.iteye.com/blog/577989
Some changes have taken place in recent work, so it is necessary to learn the spring annotations.
On the Internet to find some examples, in general, compared to the soil, most of the reprint excerpt, follow the instructions to get down at all can not run, simply go through this muddy water, here leave thousand imprint.
This time, let's build a very simple Web application, from controller to DAO. R
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
Filter Type
Examples Expression
Description
Annotation
Org.example.SomeAnnotation
Target class conforming to Someannoation
Assignable
Org.example.SomeClass
Specify the full name of class or interface
Aspectj
Org.example. *service+
AspectJ Language method
Regex
Org\.example\. default.*
Regelar Expres
Error in loading TX: annotation-driven by spring
The cvc-complex-type.2.4.c: the matching wildcard is strict, but no declaration can be found for element 'tx: annotation-driven '.
The reason is that Tx is not configured properly. In the spring configuration file, modify Xmlns = "http://www.springframewo
spring2.5 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
@Resource By default is assembled by name, only if the bean that matches the name is not found to assemb
ThanksItcastFree video released.
UseFieldInjection (for annotation)
Manual assembly or automatic assembly can be used to inject dependent objects. manual assembly is recommended in actual applications.
You can also use@ AutowiredOr@ ResourceWe needXMLConfigure the following information in the configuration file:
Xmlns: xsi = http://www.w3.org/2001/XMLSchema-instance
Xmlns: context =Http://www.springframework.org/schema/context
@Valid
Spring MVC is a hibernate-validate, the first step must be the guide package, it ignores
Validation annotations that can be used
@NotNull value cannot be empty
@Null value must be empty
@Pattern (regex=) string must match regular expression
@Size (min=,max=) The number of elements in the collection must be between Min and Max
@CreditNumber (ignorenondigitcharacters=) string must be a credit card number (verified by US standards)
@Email
Four basic annotations in SPRINGMVC:@Component, @Repository @Service, @ControllerLook at the literal meaning, easy but not out of three of them:@Controller Control layer, that's our action layer.@Service The business Logic layer, which is our service or manager layer@Repository Persistence layer, which is what we often call the DAO layerand @Component (literally
Found a problem, very egg ache.Our project is composed of n projects, the periphery is the Web project, the internal engineering is packaged into jars, and put into the peripheral engineering Web-inf/libThe internal engineering uses spring annotations, such as @service, @Controller, etc., can be scanned before hitting the jar package, but after the jar package, it will not be scanned, the report nosuchbeane
Initial development of annotated typeTwo commonly used annotations:@Controller: Is the most commonly used annotation in SPRINGMVC, which can help define the current class as a spring-managed bean, specifying that the class is a controller that can be used to accept requests. Identifying the current class is a concrete implementation of the control layer@requestMapping: Put on a method to specify the path to
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.