Class SpringChainApp
This class demonstrates blockchain-spring autoconfiguration (AC-10):
a single @SpringBootApplication annotation plus blockchain.*
properties in application.yml is all that is needed to create, configure,
and start a BlockchainNode as a Spring bean.
Autoconfigured beans (from blockchain-spring)
BlockchainNode— started automatically on application context refreshTransactionMempool— wired to the node lifecycleBlockchainHealthIndicator— exposed via Spring Boot Actuator
Demo-specific beans (defined here)
demoWallet()— a randomly-generated wallet used by the REST controller to sign submitted transactions. In production, load from an encrypted keystore.objectMapper()— registersJavaTimeModuleso thatInstantfields inBlockandNodeStatusserialize as ISO-8601 strings, matching the format used byBlockSerializer.MAPPER.
Run with Maven
mvn spring-boot:run -pl examples/spring-boot-demo
Available endpoints
GET /api/status— node status (height, mempool size, engine name)GET /api/chain— full block list as JSON arrayGET /api/chain/{idx}— single block by indexPOST /api/transactions— submit a payment transactionPOST /api/mine— manually trigger block miningGET /actuator/health— Spring Actuator health check
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates, configures, and starts the BlockchainNode as a Spring bean.Provides a freshly generated demo wallet for signing REST-submitted transactions.static voidApplication entry point.com.fasterxml.jackson.databind.ObjectMapperConfigures Spring MVC's JacksonObjectMapperso thatjava.time.Instantfields serialize as ISO-8601 strings (e.g.voidstopNode()Stops the node cleanly when the Spring context shuts down.
-
Constructor Details
-
SpringChainApp
public SpringChainApp()
-
-
Method Details
-
main
Application entry point.- Parameters:
args- command-line arguments (passed through to Spring)
-
blockchainNode
Creates, configures, and starts the BlockchainNode as a Spring bean. Defined manually here because blockchain-spring autoconfiguration requires the full network stack; this demo uses in-memory storage only. -
stopNode
@PreDestroy public void stopNode()Stops the node cleanly when the Spring context shuts down. -
demoWallet
Provides a freshly generated demo wallet for signing REST-submitted transactions.The wallet's private key is generated at startup using
WalletManagerand is never persisted or logged (NFR-SEC-01). The wallet's address is printed to the application log atINFOlevel so operators know which signer is active for the demo session.In a production application, replace this bean with one that loads from an encrypted keystore via
WalletManager.exportKeystore(Wallet, String)/WalletManager.importKeystore(String, String).- Returns:
- a new, randomly generated
Wallet
-
objectMapper
@Bean public com.fasterxml.jackson.databind.ObjectMapper objectMapper()Configures Spring MVC's JacksonObjectMapperso thatjava.time.Instantfields serialize as ISO-8601 strings (e.g."2026-06-06T10:00:00Z") instead of numeric timestamp arrays.Spring Boot 4 removed the
Jackson2ObjectMapperBuilderCustomizerinfrastructure. Declaring anObjectMapperbean directly is the supported replacement and gives full control over serialization behavior.This matches the format produced by
BlockSerializer.MAPPERused internally by all storage backends, keeping REST output consistent with persisted JSON payloads.- Returns:
- a fully configured
ObjectMapper
-