Expert.one.on.one.j2ee.development.without.ejb notes

xiaoxiao2021-03-06  81

Spring: IOC AOP

1. How to read by the bean factory bean (p178) public class TextStyle {private String fontName = "default"; private int fontSize = 9; private boolean bold = false; private boolean italic = false; public void setFontName (String fontName) { This.FontName = fontname;} public string getFontName () {return fontname;} ...}

arial 12 Times 10 true True < / Value>

Resource resource = new classpathresource ("styles.xml"); - 1ListableBeanFactory bf = new xmlbeanfactory; - 2

TextStyle MyStyle = (TextStyle) bf.getBean ("MyStyle"); TextStyle YourStyle = (TextStyle) bf.getBean ("YourStyle");

1, 2 Can Be Replaced to

NO-XML: ListableBeanFactory bf = new DefaultListableBeanFactory (); PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader (bf); Resource resource = new ClassPathResource ( "styles.properties"); reader.loadBeanDefinitions (resource);

XML: ListableBeanFactory bf = new DefaultListableBeanFactory (); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader (bf); Resource resource = new ClassPathResource ( "styles.xml"); reader.loadBeanDefinitions (resource); 2.Autowire (p185) 2.1 byType avoid display Set REF in the configuration, but automatically looks out according to the attribute type of the bean. 2.2 BYNAME matches according to the property name of the bean.

3.Dependency checking type checking support: simple (primitives and Strings); objects; all (simple & objects) eg

5.Constructor Wiring Upioc includes Dependency Look Up (EJB) Dependency InjectionDependency Injection Injection Injection Constructor Injection

Spring bean factory can also provide autowiring for constructors, define sequence index. true

6.Lifecycle Callbacks (p188) 6.1 Two callback interfaces provided after property setting and on bean factory shutdown.public interface InitializingBean {void afterPropertiesSet () throws Exception;}

Public interface disposablebean {void destroy () throws exception;

6.2 Declarative specification of callback methods, not involve Spring dependencies. 7. Complexy property value. (P190 ) Bean Factory Support Complexy Property Value Such As List, Map, Array ETC.

8.jndi Resource (P199) jdbc / myds

Note That The JNDI Name "JDBC / MYDS" WILL GET Resolved to "java: comp / env / jdbc / myds".

9.ServletContextSpring WebApplicationContext /Web-inf/applicationContext.xml.

public class MyServlet extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {ServletContext sc = getServletContext (); WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext (sc); MyService myService = (MyService) wac.getBean ( "myService "); request.setAttribute (" message ", myService.getMessage ()); request.setAttribute (" headline ", myService.getHeadline ()); request.getRequestDispatcher (". / myview.jsp ") forward (request, response }}

10.StructAction - controllerpublic ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) Action will automatically receive a ActionForm (if configured accordingly in strutsconfig.xml)

ActionForm - modelpublic ActionErrors validate (ActionMapping mapping, HttpServletRequest request): invoked after population with request parameters but before the invocation of execute.controller Actioninterceptor -command / form ActionFormvalidator ActionForm or declarative rulesvalidation errors holder ActionErrorsmodel ActionForm, manual request attributesview reference ActionForward

11.Spring MVCcontroller Controller, or any handler Object with an adapterinterceptor HandlerInterceptor, or AOP MethodInterceptorcommand / form Any command or form JavaBeanvalidator Validatorvalidation errors holder Errorsmodel Map of arbitrary model objects in ModelAndViewview reference View instance or view name in ModelAndView

12. REQUEST-Driven & Event-DrivenRequest-Driven: Struct; Spring; WebWork2event-Driven: TapeStry; Java Server Face (Similar To .NET) RAD

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

New Post(0)