Monthly Archives: April 2010

IOC/DI的好处

   把主对象建好之后,再通过容器注入它的从属对象。

   这是一种解耦:

     1.主对象的构造不依赖于从属对象。

     2.主对象不用考虑去哪找从属对象,容器会处理好这件事。

[Relearn Spring] 2.1 IoC – Misc 1

1. BeanFactory V.S. ApplicationContext

  BeanFactory only handles the managements of beans.

  ApplicaitonContext is build upon BeanFactory (by inheritance) but add enterprise support to it, such as AOP/Resource etc.

2. BeanDefinition will hold the metadata for beans, such as  scope, lazy-initialization and so on.

3. You can use your self-defined to create your bean, just by XML configuration

 

 <bean id="exampleBean"
factory-bean="serviceLocator"
factory-method="createInstance"/>

  

3.

 <ref local="someBean"/> 
   

means that the container will try to seek this bean in the same xml file.

4.

<bean id="beanOne" class="ExampleBean" depends-on="manager"/>

will tell the container to initialize "beanOne" after it initializes "manager"

5.Inject "local" variable

package fiona.apple;
// no more Spring imports!
public abstract class CommandManager {
public Object process(Object commandState) {
// grab a new instance of the appropriate Command interface
Command command = createCommand();
// set the state on the (hopefully brand new) Command instance
command.setState(commandState);
return command.execute();
}
// okay... but where is the implementation of this method?
protected abstract Command createCommand();
}

<bean id="commandManager" class="fiona.apple.CommandManager">
<lookup-method name="createCommand" bean="command"/>
</bean>

中国各银行有没有真正靠的住的网银?

中国的网银的用户体验普遍比较差,这可能跟银行没有专门做软件的产品经理有关。

如果说这个还可以容忍,那各种BUG就很恶心了。

某行的网银用的是C/S程序,我一次登录时,死活登录不上,老说我密码不对;后来用另一台电脑登录,就登上了。

今天遇到的这个更搞笑。这是另一家著名银行网银给我的错误提示:

"对不起,操作未成功!role.user_has_not_right_status "

 

Autowire一个 FactoryBean时,代码里要把变量的类型定义为FactoryBean.getObjectType()



  <bean id="myCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> 为例,

     //正确
     @Autowired
     private Ehcache myCache;  //因为 EhCacheFactoryBean.getObjectType() == Ehcache 

     //错误:
     @Autowired
     private Cache myCache;  //会报错,虽然Cache是Ehcache的子类。具体错误为“No unique bean of type [net.sf.ehcache.Cache] is defined”

[MVC]分解一个Action/Controller的功能点/测试点

开发/测试一个 Struts Action/Spring Controller时,要注意覆盖到以下所有功能点/测试点.

  1.Form Rendering   

     a.first rendering

     b.rendering after submission

        i.successful submission

       ii.failed submission

  2.Validation

     a.Show Field Errors/Action Errors in validation fails

  3.Show Correct Results

     a. What if no result?

     b. Results are too few to be paginated.

     c. Results are so many that they should be paginated.

  4.Show Error Results

     a.Show Field Errors

     b.Show Action Errors

  5.Authorization Control

     a.Permitted

     b.Not Permitted