Introduction to Spring programming Top ten questions to answer

Source: Internet
Author: User
Tags implement key mysql net zip log4j
Programming | solutions | questions

  1. How to learn spring?

You can learn spring in the following ways:

(1) Examples of mvc-step-by-step and sample directories in the doc directory in spring download packages are examples of better spring development.

(2) Appfuse integrates several of the most popular open source lightweight frameworks or tools Ant,xdoclet,spring,hibernate (IBATIS), Junit,cactus,strutstestcase,canoo ' s Webtest,struts menu,display Tag library,oscache,jstl,struts.

You can learn spring by appfuse the source code.

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 starter book that introduces the concepts of reversal control and dependency injection, as well as spring's bean management, the mvc,spring of spring and the combination of Hibernte,ibatis.

(4) The Chinese Forum of Spring Learning

Springframework Chinese Forum (http://spring.jactiongroup.net)

Spring section of the Java View Forum (http://forum.javaeye.com)

  2, using the Spring framework programming, console print out Log4j:warn please initialize the log4j system properly?

Show that your log4j.properties is not configured. Please put the log4j.properties in the classpath of the project, the Eclipse Classpath is the bin directory, because the files under the compiled src directory will be copied to the Bin directory, so you can put log4j.properties into the src directory.

Here is a log4j.properties example:

Log4j.rootlogger=debug,stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%5p (%f:%l)-%m%n

  3, appear java.lang.NoClassDefFoundError?

In general, it is because you did not put the necessary jar package into lib.

For example, if you want to adopt spring and hibernate (with transactional support), you need Hibernat.jar, Aopalliance.jar, Cglig.jar, and so on besides Spring.jar. A few jar packages under Jakarta-commons.

http://www.springframework.org/download.html Download the spring Development Kit, offering two kinds of zip packages
Spring-framework-1.1.3-with-dependencies.zip and Spring-framework-1.1.3.zip, I suggest you download Spring-framework-1.1.3-with-dependencies.zi P. After this zip decompression more than the latter a Lib directory, which has Hibernate, Java, dom4j, Aopalliance, jakarta-commons and other common packages.

  4, java.io.FileNotFoundException:Could not open Class path resource [... hbm.xml], prompted not to find the XML file?

There are generally two reasons for this:

(1) The XML file is not in Classpath.

(2) The XML name in Applicationcontext-hibernate.xml does not have a package name. Like what:



User.hbm.xml
Wrong, instead:
Com/yz/spring/domain/user.hbm.xml



Net.sf.hibernate.dialect.MySQLDialect
true


  5. Org.springframework.beans.NotWritablePropertyException:Invalid Property Postdao of Bean class?

The exception occurred because of the error in property name in Application-xxx.xml.

The name of the

Like what

public class Postmanageimpl extends Basemanage implements Postmanage {
Private Postdao DAO = null;
public void Setpostdao (Postdao Postdao) {
This.dao = Postdao;
}
}

Then the definition of XML should be:


to
wrong


  6. How do I implement transaction management in spring?

First, if you use MySQL, make sure MySQL is InnoDB type.

The control of transaction management should be put into the business logic layer. You can write a javabean that handles business logic, call DAO in that JavaBean, and then incorporate the bean's approach into spring's transaction management.

For example, the XML file is defined as follows:

Class= "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >


propagation_required
propagation_required
propagation_required






Com.yz.spring.service.implement.UserManageImpl is our JavaBean for the realization of business logic. We declare the transaction support through the parent element.

  7. How to manage more JavaBean under the spring framework?

The more javabean, the greater the spring configuration file, which is difficult to maintain. In order to make the configuration clear, we can put the JavaBean classification management, in different configuration files. All XML is loaded at the same time when the application starts.

Like what:

The JavaBean of the DAO layer is placed in the Applicationcontext-hibernate.xml, and the JavaBean of the business logic layer is placed in the applicationcontext-service.xml. The following code is then invoked 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?

Can be automatically loaded by the Web container by defining Web.xml.


Context
Org.springframework.web.context.ContextLoaderServlet
1


contextconfiglocation
/web-inf/applicationcontext-hibernate.xml
/web-inf/applicationcontext-service.xml

  9, how to configure the log4j in spring?

Add the following code to the Web.xml.


log4jconfiglocation
/web-inf/log4j.properties

  10. How do I get a deeper understanding of the spring framework by solving the programming problem of getting started with the spring framework?

You should go and see these two books. The two books were written by Rod Johnson, Spring's author.

Expert one on one Java EE design and Development
Expert one on one Java Development without EJB

You should also see Martinfowler's inversion of control containers and the Dependency injection.

Http://www.martinfowler.com/articles/injection.html
 
Read the spring documentation again.

Http://www.jactiongroup.net/reference/html/index.html (Chinese version, not all translations)

There is more practice it.



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.