Autumn Framework is a light-weight, educational project inspired by the Spring Framework. It was created with the purpose of understanding how Spring works under the hood.
- Simple, but powerful IOC container with Singleton and Prototype scopes support
- Dependency Injection using @Inject annotation
- Component scan using @Injectable annotation with scopes support
- Inject properties from application.properties using @InjectProperty annotation
- Straightforward Java configuration
- Flexible object configurators and proxy configurators
- Generates warnings when deprecated classes are called
- Helps to understand Spring Core concepts in a simplified manner
public class JavaConfig implements Config {
...
@Override
public <T> Class<? extends T> getImplClass(Class<T> ifc) {
return ifc2ImplClass.computeIfAbsent(ifc, aClass -> {
Set<Class<? extends T>> classes = scanner.getSubTypesOf(ifc)
.stream()
.filter(clazz -> clazz.isAnnotationPresent(Injectable.class))
.collect(Collectors.toSet());
...
});
}
}
Create Injectable classes with @Injectable and inject dependencies using @Inject.
import com.markhmnv.autumnframework.annotation.Inject;
@Injectable
public class DemoService {
@Inject
private DemoRepository demoRepository;
...
}
Or use @RequiredArgsConstructor from Lombok
import lombok.RequiredArgsConstructor;
@Injectable
@RequiredArgsConstructor
public class DemoService {
private final DemoRepository demoRepository;
...
}
Inject properties from application.properties using @InjectProperty.
@Injectable
public class DemoService {
@InjectProperty
private String secret;
...
}
Create an instance of ApplicationContext via AutumnApplication.run(). After that, simply call context.getObject() to get full-featured objects.
public class Demo {
public static void main(String[] args) {
ApplicationContext context = AutumnApplication.run(Demo.class);
DemoController demoController = context.getObject(DemoController.class);
...
}
}