A bunch of questions on Spring 3 framework

ぐ巨炮叔叔 提交于 2019-12-04 14:18:02

(1) Do I ever need manual creation of ApplicationContext? Do I ever need second instance of AplicationContext?

Spring is typically usd in two environments - in web development and in desktop applications/standalone servers. In the former case the ApplicationContext is created automatically via ContextLoaderListener defined in web.xml or WebContextInitializer in Servlet 3.0 container.

In the latter case (standalone application) you are responsible for creating and destroying the application context.


(2) We have the following config instructions:

<context:component-scan base-package=".."/> provides all the functionality of <context:annotation-config/> plus (surprise!) component scanning. <mvc:annotation-driven/> is completely independent and it recognizes annotations like @Controller.


[...]The entered date should be converted to Date property of Project object[...]

Register custom editor within @Controller:

@Controller
public class FooController {
    @InitBinder
    public void binder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            public void setAsText(String value) {
                try {
                    setValue(new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(value));
                } catch (ParseException e) {
                    setValue(null);
                }
            }
        });
    }
}

[...]how can I know which annotations can be used in my project?[...]

I found this awesome annotations support sheet some time ago (I am not an author). It will tell you which annotations are enabled when.


All that can be found in my classpath

@Inject is enabled if it is found on the CLASSPATH, other annotations need to be enabled manually, see above.


So looks like I cannot use Spring AOP without aspectJ library?

You can use Spring without CGLIB if you only use interface proxies (i.e. you only apply aspects on classes implementing at least one interface). Otherwise you need CGLIB to dynamically create subclasses.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!