spring abstract class

the modern spring framework has now been able to DI for abstract class properties.

For example:

public abstract class AbstractCacheReader<T extends AbstractMessage> implements ModelCacheReader<T> {

    T models;

    @Value("${....cache.deployment.directory}")
    protected String CACHE_DEPLOYMENT_DIRECTORY;
....
}

with concrete class

@Component
@Slf4j
@Setter
public class ABCCacheReader extends AbstractCacheReader<ABC.ABCModels> implements ModelCacheReader<ABC.ABCModels> {

    public ABCCacheReader() {
..
        models = ABC.ABCModels.newBuilder().build();
    }
....
}

the CACHE_DEPLOYMENT_DIRECTORY would be properly wired onto

ABCCacherReader bean.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s