How to Learn spring?

Source: Internet
Author: User

1. How to Learn spring?
You can learn spring in the following ways:
(1) examples in the MVC-step-by-step and sample directories under the doc directory in the spring download package are good examples of spring development.

(2) appfuse integrates several of the most popular open source lightweight frameworks or tools such as ant, XDoclet, spring, Hibernate (ibatis), JUnit, cactus, strutstestcase, canoo's webtest, struts menu, display tag library, Oscache, jstl, and struts.
You can use the source code of appfuse to learn spring.
Appfuse Website: http://raibledesigns.com/wiki/Wiki.jsp? Page = appfuse

(3) Spring Development Guide (Xia Xin) (http://www.xiaxin.net/Spring_Dev_Guide.rar)
A spring entry book that introduces the concepts of Reverse Control and dependency injection, spring bean management, spring MVC, spring, hibernte, and ibatis.

(4) Chinese forum for spring Learning
Springframework Chinese Forum (http://spring.jactiongroup.net)
Java line of sight Forum (http://forum.javaeye.com) Spring topic

2. Using Spring framework programming, the console prints log4j: Warn please initialize the log4j system properly?
It indicates that your log4j. properties is not configured. Set log4j. properties is placed in the classpath of the project, and the classpath of eclipse is the bin directory. Since the files under the src directory will be copied to the bin directory after compilation, you can set log4j. put properties in the src directory.
Here is an example of log4j. properties:

Log4j. rootlogger = debug, stdout
Log4j. appender. stdout = org. Apache. log4j. leleappender
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
Log4j. appender. stdout. layout. conversionpattern = % d % 5 p (% F: % L)-% m % N

3. Why does java. Lang. noclassdeffounderror appear?
Generally, it is because you have not put the necessary jar package into Lib.

For example, if you want to use spring and hibernate (with transaction support), except spring. hibernat is also required in addition to jar. jar, aopalliance. jar, cglig. jar and several jar packages under Jakarta-commons.

Http://www.springframework.org/download.htmldownload spring development kit, two zips
. This zip package has an additional lib directory than the latter, including common packages such as Hibernate, J2EE, dom4j, aopalliance, and Jakarta-commons.

4. java. Io. filenotfoundexception: cocould not open class path resource [... HBM. xml]. Why can't I find the XML file?
There are generally two reasons:
(1) The XML file is not in classpath.
(2) The XML name in the applicationContext-hibernate.xml does not contain the package name. For example:
<Bean id = "sessionfactory" class = "org. springframework. Orm. hibernate. localsessionfactorybean">
<Property name = "datasource"> <ref bean = "datasource"/> </property>
<Property name = "mappingresources">
<List>
<Value> User. HBM. xml </value> error: <value> COM/YZ/spring/domain/user. HBM. xml </value>
</List>
</Property>
<Property name = "hibernateproperties">
<Props>
<Prop key = "hibernate. dialect"> net. SF. hibernate. dialect. mysqldialect </prop>
<Prop key = "hibernate. show_ SQL"> true </prop>
</Props>
</Property>
</Bean>

5. org. springframework. Beans. notwritablepropertyexception: Invalid property 'postdao 'of Bean class?
An exception occurs because of a property name error in the application-xxx.xml.
<Property name = "..."> the name is related to the bean's set method, and must be case sensitive.
For example
Public class postmanageimpl extends basemanage implements postmanage {
Private postdao Dao = NULL;
Public void setpostdao (postdao ){
This. Dao = postdao;
}
}
The XML definition should be:
<Bean id = "postmanage" parent = "txproxytemplate">
<Property name = "target">
<Bean class = "com. YZ. Spring. Service. Implement. postmanageimpl">
<Property name = "postdao"> <ref bean = "postdao"/> </property>
<Property name = "Dao"> <ref bean = "postdao"/> </property> Error
</Bean>
</Property>
</Bean>

6. How to Implement Transaction Management in spring?
First, if MySQL is used, determine that MySQL is of the InnoDB type.
The control of transaction management should be placed on the business logic layer. You can write a JavaBean for processing business logic, call Dao In the JavaBean, and then incorporate the bean method into Spring transaction management.

For example, the XML file is defined as follows:
<Bean id = "txproxytemplate" abstract = "true"
Class = "org. springframework. transaction. Interceptor. transactionproxyfactorybean">
<Property name = "transactionmanager"> <ref bean = "transactionmanager"/> </property>
<Property name = "transactionattributes">
<Props>
<Prop key = "Save *"> propagation_required </prop>
<Prop key = "Remove *"> propagation_required </prop>
<Prop key = "*"> propagation_required </prop>
</Props>
</Property>
</Bean>

<Bean id = "usermanage" parent = "txproxytemplate">
<Property name = "target">
<Bean class = "com. YZ. Spring. Service. Implement. usermanageimpl">
<Property name = "userdao"> <ref bean = "userdao"/> </property>
</Bean>
</Property>
</Bean>

Com. YZ. Spring. Service. Implement. usermanageimpl is our JavaBean that implements business logic. We declare its transaction support through the parent element.

7. How to manage more JavaBean under the Spring framework?
The more JavaBean, the larger the spring configuration file, which is difficult to maintain. To make the configuration clear, we can classify and manage the JavaBean in different configuration files. When the application starts, all XML files are loaded at the same time.
For example:
The JavaBean of Dao layer is put into the applicationContext-hibernate.xml, And the JavaBean of commercial logic layer is put into the applicationContext-service.xml. Then call the following code in the startup class to load all applicationcontext.

String [] paths = {"com/YZ/spring/Dao/hibernate/applicationContext-hibernate.xml ",
"Com/YZ/spring/service/applicationContext-service.xml "};
CTX = new classpathxmlapplicationcontext (paths );

8. How to load applicationcontext in Web applications?
You can define web. XML to be automatically loaded by web containers.

<Servlet>
<Servlet-Name> context </servlet-Name>
<Servlet-class> org. springframework. Web. Context. contextloaderservlet </servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>

<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/applicationContext-hibernate.xml </param-value>
<Param-value>/WEB-INF/applicationContext-service.xml </param-value>
</Context-param>

9. How to configure log4j in spring?
Add the following code to Web. xml.
<Context-param>
<Param-Name> log4jconfiglocation </param-Name>
<Param-value>/WEB-INF/log4j. properties </param-value>
</Context-param>

10. How can I better understand the Spring framework after the Spring framework programming problem is solved?
You should check these two books. These two books are written by spring author rod Johnson.
Expert one on one J2EE design and development
Expert one on one J2EE development without EJB
You should also look at the inversion of control containers and the dependency injection pattern of martinfowler.
Http://www.martinfowler.com/articles/injection.html

Take a good look at the spring documentation.
Http://www.jactiongroup.net/reference/html/index.html (Chinese version, not all translated)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.