Take on the above

Custom object behavior


.net piece ( The environment is vs2012+Spring.Core.dll v1.31

 public class lifeCycle :
Spring.Objects.Factory.IInitializingObject,
System.IDisposable,
Spring.Objects.Factory.IObjectFactoryAware,
Spring.Objects.Factory.IObjectNameAware
{
public Spring.Objects.Factory.IObjectFactory OFactory { get; set; }
public String Name { get; set; }
public void initMethod(){}
public void destroyMethod() {}
public void AfterPropertiesSet(){
initMethod();
}
public void Dispose(){
destroyMethod();
}
public Spring.Objects.Factory.IObjectFactory ObjectFactory{
set { OFactory = value; }
}
public string ObjectName{
set { Name = value; }
}
}
public class CustomFactory :
Spring.Objects.Factory.IFactoryObject
{
public object GetObject(){
return "1";
}
public bool IsSingleton{
get { return false; }
}
public Type ObjectType{
get { return typeof(string); }
}
}
<object id="lifeCycle"
type="SpringBase.lifeCycle, SpringBase"
init-method="initMethod"
destroy-method="destroyMethod" />
<object id="customFac" type="SpringBase.CustomFactory, SpringBase"/>

java piece ( The environment is Maven+Jdk1.7+IntelliJ IDEA 12.1.4

package springdemo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
public class LifeCycle implements
InitializingBean,
DisposableBean,
BeanFactoryAware, BeanNameAware {
private BeanFactory oFactory;
private String name;
public void initMethod(){}
public void destroyMethod() {}
@Override
public void afterPropertiesSet() throws Exception {
initMethod();
}
@Override
public void destroy() throws Exception {
destroyMethod();
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
oFactory=beanFactory;
}
@Override
public void setBeanName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public BeanFactory getoFactory() {
return oFactory;
}
}
class CustomFactory implements FactoryBean<String>{
@Override
public String getObject() throws Exception {
return "1";
}
@Override
public Class<?> getObjectType() {
return String.class;
}
@Override
public boolean isSingleton() {
return false;
}
}
 <bean id="lifeCycle" class="springdemo.LifeCycle"
init-method="initMethod"
destroy-method="destroyMethod" />
<bean id="customFac" class="springdemo.CustomFactory" />

java and Csharp Common ground

  1. IObjectFactoryAware|BeanFactoryAware as well as IObjectNameAware|BeanNameAware
    The properties or methods of the implemented interface will be initialized after the container is initialized spring Automatic call assignment , Just change the method body
  2. IInitializingObject|InitializingBean Interface AfterPropertiesSet Method
    After the completion of the attribute assignment , It can also be used. init-method Nodes come and spring Frame decoupling
  3. IDisposable|DisposableBean Interface destroy Method is called when the object is released ,
    It can also be used. destroy-method Nodes come and spring Frame decoupling
  4. IFactoryObject|FactoryBean Create a factory class for ,
    adopt id call Ioc The container returns getObject The return value of the method is not a factory class ,
    In the previous section, getting the properties of an object inherits this interface ,isSingleton Returns whether this object is a singleton ,
    ObjectType|getObjectType Return object type
  5. IObjectFactoryAware|BeanFactoryAware Get current Ioc The container of
  6. IObjectNameAware|BeanNameAware Get the name of the object in the container

Ⅶ.spring Every bit of -- More articles on custom object behavior

  1. Ⅷ.spring Every bit of -- Abstract objects and sub objects

    Take on the above Abstract objects and sub objects .net piece ( The environment is vs2012+Spring.Core.dll v1.31) public class parent { public string Name { get; ...

  2. Ⅵ.spring Every bit of -- Custom type converter

    Take on the above Custom type converter .net piece ( The environment is vs2012+Spring.Core.dll v1.31) public class CustomeConverter : TypeConverter{ ...

  3. Ⅹ.spring Every bit of --IObjectPostProcessor( Object postprocessor )

    Take on the above IObjectPostProcessor( Object postprocessor ) The premise is that the object implementing the interface is registered with the current container C#: By inheritance AbstractObjectFactory Object's AddObjectPostPro ...

  4. Spring Data JPA Custom objects receive query result sets

    Spring Data JPA brief introduction Spring Data JPA yes Spring be based on ORM frame .JPA The specification is based on a package JPA Application framework , It enables developers to access and access the database with minimal code ...

  5. Ⅴ.spring Every bit of -- Refer to members of other objects or types

    Take on the above Refer to members of other objects or types .net piece ( The environment is vs2012+Spring.Core.dll v1.31) public class Person { public string Name { ...

  6. XI.spring Every bit of --IObjectFactoryPostProcessor( Factory post processor )

    Take on the above IObjectFactoryPostProcessor( Factory post processor )) The premise is that the object implementing the interface is registered with the current container Directly inherited objects call this postProcessBeanFactory Method , The parameter is work ...

  7. Ⅸ.spring Every bit of --IObjectFactory And IFactoryObject The miscellaneous talk of

    Take on the above ObjectFactory And IFactoryObject The miscellaneous talk of .net piece ( The environment is vs2012+Spring.Core.dll v1.31) public class parent { pu ...

  8. Ⅱ.spring Every bit of -- object

    Take on the above Various instantiations of objects .net piece ( The environment is vs2012+Spring.Core.dll) Modify the original PersonDao The object is public class PersonDao : IPersonDao ...

  9. Chapter four Spring.Net How to manage your classes ___ Custom object behavior

    Spring.Net It's always about ” Configure the application “, There is a requirement that is not commonly used in actual development , But it's very useful -> Configure the behavior of objects ,Spring.Net It can also be perfectly realized .Spring.Net Through a few specialized ...

Random recommendation

  1. Can improve the efficiency of development Eclipse Practical operation

    A good workman does his work well , You must sharpen your tools first . For programmers ,Eclipse It's one of them “ device ”. This article will be from Eclipse Shortcut keys and practical skills are introduced in two chapters .Eclipse After the shortcut key is used , No mouse , Can be programmed and developed , Avoid mouse separation ...

  2. CentOS7 yum Installation configuration

    One . Installation package yum install gcc Two .linux Lower installation # download wget http://download.redis.io/releases/redis-3.0.0.tar.gz tar ...

  3. 404 Not Find When using Owin with OAuth

    In the use of Owin+OAuth when , Step by step when testing , In use OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = ...

  4. cf475A Bayan Bus

    A. Bayan Bus time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. java Overview of multithreading knowledge points

    This is just an overview , Very simple list of knowledge points , I need to go through it in my head , If you are not familiar with some aspects , It is suggested to use the network resources to learn . 1. Threads . Process concept Concept Thread state and its transition 2. Deadlock . The prevention of . solve 3.jdk Thread real ...

  6. javase Learning summary 2

    Trigonometric function method Math.sin(radians):Math.sin(Math.PI/6)=0.5 Math.cos(radians):Math.cos(Math.PI/3)=0.5 Math.tan( ...

  7. ubuntu Next use ss-qt5

    First step :. install ss-qt5 adopt PPA Source installation , Support only Ubuntu 14.04 Or later . Open the terminal sudo add-apt-repository ppa:hzwhuang/ss-qt5 sudo a ...

  8. Spring Summary of the principle of

    One .Bean The life process of Bean We can learn from Servlet The life process of , Understanding its life process is very helpful for both thinking and future use : Bean It can be loaded in two ways , They are using BeanFactory ...

  9. plink:ped Format conversion to bed Format

    The command line is as follows : plink --file FILENAME --make-bed --out FILENAME first FILENAME The suffix of is .ped and .map, The second generated FILENAME The suffix of is .b ...

  10. ASP.NET:EntityFramework Realization Session

    ASP.NET default InProc Mode Session It's a waste of memory and data loss when the website restarts ,SQLServer Mode Session Only support SQL Server Command line configuration is required . Use EntityFram ...