Spring Getting Started Programming Problem Collection

xiaoxiao2021-03-06  42

Http://blog.9cbs.net/yzhz/archive/2005/01/17/springqa.aspx Transfer from an article from the Java Line Forum, I hope to help Spring beginners: 1, how to learn Spring? You can learn Spring through the following ways: (1) Spring Download Pack MVC-STEP-BY-STEP and SAMPLE directory in the Spring Directory are examples of preferred Spring development. (2) AppFuse integrates the current most popular lightweight lightweight framework 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 through the AppFuse source code. AppFuse website: http://raibledesigns.com/wiki/wiki.jsp? Page = Appfuse (3) Spring Development Guide (Htttp://www.xiaxin.net/spring_dev_guide.rar) A spring entry Books, the concept of reverse control and dependency injections, as well as Spring Bean management, Spring's MVC, Spring, and Hibernte, IBATIs. (4) Spring Research Chinese Forum Springframework Chinese Forum (http://spring.jActiongroup.net) Spring section 2 of http://forum.javaeye.com, uses Spring framework programming, console prints Log4j : WARN PLEASE INITIALIZE THE LOG4J SYSTEM PROPERLY? Explain that your log4j.properties is not configured. Please put the log4j.properties in the ClassPath of the project, Eclipse's classpath is a bin directory, so you can put the log4j.properties in the SRC directory because the files in the SRC directory are copied to the bin directory. Here is an example log4j.properties: 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 For example, you have to use Spring and Hibernate, you need hibernat.jar, aopalliance.jar, cglig.jar, Jakarta-Commons, in addition to Spring.jar. http://www.springframework.org/download.html Download Spring Development Pack, provide two zip packs 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.zip.

This zip decompression is more than one lib directory than the latter, where Hibernate, J2EE, DOM4J, AOPALLIANCE, JAKARTA-Commons, etc. are common packages. 4, java.io.filenotfoundexception: could not open class path resource [.... hbm.xml], prompt not to find an XML file? The reason is generally two: (1) The XML file is not in the ClassPath. (2) The XML name in ApplicationContext-Hibernate.xml does not have a package name. For example: user.hbm.xml wrong, change to: COM / YZ / SPRING / DOMAIN / user.hbm.xml net.sf.hibernate.diaalect.mysqldiaalect The name of Name is related to the bean's SET method, and paying attention to case.

For example public class PostManageImpl extends BaseManage implements PostManage {private PostDAO dao = null; public void setPostDAO (PostDAO postDAO) {this.dao = postDAO;}} should be so defined xml: Property name = "dao"> 6, how to implement transaction management in Spring? First, if you use mysql, determine MySQL to the InnoDB type. The control of transaction management should be placed in the business logic layer. You can write a JavaBean that handles business logic, call DAO in the JavaBean, then incorporate the BEAN's method into Spring's transaction management.

For example: xml file is defined as follows: PROPAGATION_REQUIRED PROPAGATION_REQUIRED PropAgation_required com.yz.spring.service.Implement. UserManageImpl is our JavaBean that implements business logic. We declare its transaction support through the Parent element. 7. How do I manage more Javabean under the Spring framework? The more javabean, the greater the Spring configuration file, which is not easy to maintain. In order to make the configuration clear, we can manage the JavaBean to manage, placed in different profiles. Load all XML simultaneously when the application starts. For example: JavaBean in the DAO layer is placed in ApplicationContext-Hibernate.xml, and the JavaBean of the business logic layer is placed in ApplicationContext-Service.xml. Then, the startup class is called 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 do I load ApplicationContext in web applications? You can automatically load by defining web.xml.

转载请注明原文地址:https://www.9cbs.com/read-58747.html

New Post(0)