Alibabacloud.com offers a wide variety of articles about spring annotations tutorial, easily find your spring annotations tutorial information here online.
1. @Inject
Javax.inject
JSR330 (Dependency injection for Java)
This is the specification in JSR330, which is implemented by the Autowiredannotationbeanpostprocessor class by dependency injection.@Inject useThe following is the use of @inject, without adding @named annotations, you need to configure the same as the variable name.@Inject @named ("MONGO") Private Mongo Mongo;2. @Autowired
Org.springframework.bean.factory
(paramname! = null) {builder.append ('); Builder.append (paramname); } throw new Httpmediatypenotsupportedexception ("Cannot extract parameter (" + BUILDER.TOSTR ING () + "): no Content-type found"); } list@ResponseBody Annotations: According to the Request Object Header section of the Accept attribute (comma-delimited), according to the type of accept, to traverse to find the httpmessageconverter can be processed;The source
@Configuration equivalent to beans, @bean equivalent to beans.The following is a typical spring configuration file (application-config.xml):Then you can use a bean like this:ApplicationContext CTX = new Classpathxmlapplicationcontext ("Application-config.xml");OrderService OrderService = (orderservice) ctx.getbean ("OrderService");Now spring Java Configuration This project provides a scheme to assemble bean
1, @controller Controller (injection service) 2, @service service (injection dao) 3, @repository dao (implement dao access) 4, @component (the normal Pojo is instantiated into the spring container, equivalent to the configuration file @Component, @Service, @Controller, @Repository Annotated classes, and incorporate these classes into the spring container for Management. the Following is a scan component tha
Because the project needs to use the Wizard Page jump effect, this project is implemented with spring MVC. At first, we thought of using spring webflow, but webflow is too cumbersome, for our not very complex jump, we seem to have the feeling of "getting rid of your teeth". So we searched online to see if there were any similar solutions, the answer on the internet is generally to ask you to inherit the abs
1, @controller Controller (injection service) 2, @service Service (injection DAO) 3, @repository DAO (Implement DAO Access) 4, @component (the normal pojo is instantiated into the spring container, equivalent to the configuration file @Component, @Service, @Controller, @Repository annotated classes, and incorporate these classes into the spring container for management.The following is a scan component that
First, create the projectProject Name: spring100804Ii. adding spring support to the project1. Create a Lib directory in your project/lib2. Add the jar package in the Lib directoryCommons-logging.jarJunit-4.10.jarLog4j.jarSpring-beans-3.2.0.release.jarSpring-context-3.2.0.release.jarSpring-core-3.2.0.release.jarSpring-expression-3.2.0.release.jarIii. Adding a configuration file to a project1. Create the Conf directory in your project/conf2. Add a confi
Spring boot is powerful because it uses the new features of the Spring 4 framework: @Conditional annotations, which enable some configurations only if certain conditions are met.
Here's how to use condition
First write a class
Package com.test.spring;
Import org.springframework.context.annotation.Condition;
Import Org.springframework.context.annotation.Conditi
An error similar to the following occurred:
Severity: Exception sending context initialized event to listener instance of class Org.springframework.web.context.ContextLoad Erlistener
Org.springframework.beans.factory.BeanCreationException:
Error creating Bean with Name ' Userserviceimpl ': Injection of autowired dependencies failed;Nested exception is org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Cn.springmvc.dao.UserDAO Cn.springmvc.service.impl.UserS
When we use the SPRNG MVC development Project, we usually use annotations, which can greatly improve our development efficiency. Implement zero Configuration. Here we re-start a spring MVC configuration from scratch. The project was developed in a fully annotated manner.
The previous build Project import jar package is no longer described.
1, modify Web. XML, the file contents are as follows:
2, Springmv
Both @Resource and @autowired are used to inject beans.In fact @resource is not a spring annotation, his package is javax.annotation.Resource need to import. However, spring supports the annotation injection.Common denominator: Both can be written on the field and setter methods. If both are written on a field, there is no need to write the setter method.The different points are as follows:First of all, say
Objective:Instead, use the spring Framework's powerful annotation feature (@Repository annotations) to automate the function of registering DAO's beans (originally configured in XML). After the change, run a direct error:Error creating Bean with Name ' Uservodao ' defined in file [D:\JSP_MyEclipse\.metadata\.me_tcat7\webapps\XYG_WEBDEV_ Sample\web-inf\classes\com\xinyiglass\springsample\dao\impl\uservodaoim
Spring boot can use @valid to verify when the post accepts an object parameter, as in the following codeWhen you create a user classThe above @notblank and @past made a judgment on how to do similar annotations to validate the dataTo create an Myconstraint interface@Retention: Used to describe the life cycle of the annotation class. It has the following three parameters:Retentionpolicy.source:
@import annotations in the spring framework@import annotations in the spring frameworkIn the previous article, the author introduced the spring Javaconfig. This is in addition to the use of traditional XML files, Spring brings new
1. Parameters for handling the URI portion of the request: @PathVariable.2. Handle the parameters of the request header section: @RequestHeader, @CookieValue@RequestHeader annotations, you can bind the value of the header portion of a request to a method parameter.@CookieValue can bind the value of the cookie in the request header to the parameters of the method.[Email protected] annotations are used to rec
that the parameters in @component la can be written or not, write the ID value of the Bean object specified, the default is the class name beginning with the letter lowercase loginaction.@Component ("La")// Public classloginaction {@AutowiredPrivateUserdaoimpl ud; /*** First find a id= "UD" bean in the IOC container based on the attribute name ' UD ' of the attribute being labeled * and then find a class in the IOC container based on the attribute type of the labeled attribute ' Userdaoimpl ' *
Add Ehcache Dependency package in 1.pom.xml2. Add ehcache configuration file under Classpath ehcache.xml3.spring configuration file Applicationcontext.xml need to be aware of adding red italic Partial configurationXmlns:cache= "Http://www.springframework.org/schema/cache" xsi: schemalocation= "Http://www.springframework.org/schema/cache http ://www.springframework.org/schema/cache/spring-cache-3.2.xsd" >4
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.