Spring Context module providing core application context functionality for dependency injection, lifecycle management, event-driven architecture, task scheduling, caching, validation, and cross-cutting concerns in Spring-based applications
—
@Component // Generic component
@Service // Business logic layer
@Repository // Data access layer (adds PersistenceExceptionTranslation)
@Controller // Web MVC controller
@Configuration // Bean definition source@Component
@Scope("prototype")
@Lazy
public class GenericComponent {
// Auto-detected by component scanning
}
@Component("customName")
public class NamedComponent {}@Service
public class UserService {
@Autowired
private UserRepository repository;
public User findById(Long id) {
return repository.findById(id);
}
}@Repository
public class JdbcUserRepository {
@Autowired
private JdbcTemplate jdbcTemplate;
public User findById(Long id) {
// DataAccessException translation applied automatically
return jdbcTemplate.queryForObject(
"SELECT * FROM users WHERE id = ?",
new UserRowMapper(),
id
);
}
}@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Service
@Transactional
public @interface TransactionalService {
String value() default "";
}
@TransactionalService
public class OrderService {
// Combines @Service and @Transactional
}@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
@Scope("prototype")
@Lazy
public @interface PrototypeComponent {
@AliasFor(annotation = Component.class)
String value() default "";
}
@PrototypeComponent
public class PrototypeScopedBean {}@Named("userService") // Equivalent to @Component
@Singleton // Equivalent to @Scope("singleton")
public class UserService {
@Inject // Equivalent to @Autowired
private UserRepository repository;
@PostConstruct
public void init() {}
@PreDestroy
public void cleanup() {}
}Install with Tessl CLI
npx tessl i tessl/maven-org-springframework--spring-context