Class SpringChainApp

java.lang.Object
com.privatechain.examples.spring.SpringChainApp

@SpringBootApplication public class SpringChainApp extends Object
Spring Boot entry point for the blockchain REST demo application.

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 refresh
  • TransactionMempool — wired to the node lifecycle
  • BlockchainHealthIndicator — 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() — registers JavaTimeModule so that Instant fields in Block and NodeStatus serialize as ISO-8601 strings, matching the format used by BlockSerializer.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 array
  • GET /api/chain/{idx} — single block by index
  • POST /api/transactions — submit a payment transaction
  • POST /api/mine — manually trigger block mining
  • GET /actuator/health — Spring Actuator health check
Since:
1.0.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates, configures, and starts the BlockchainNode as a Spring bean.
    Provides a freshly generated demo wallet for signing REST-submitted transactions.
    static void
    main(String[] args)
    Application entry point.
    com.fasterxml.jackson.databind.ObjectMapper
    Configures Spring MVC's Jackson ObjectMapper so that java.time.Instant fields serialize as ISO-8601 strings (e.g.
    void
    Stops the node cleanly when the Spring context shuts down.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringChainApp

      public SpringChainApp()
  • Method Details

    • main

      public static void main(String[] args)
      Application entry point.
      Parameters:
      args - command-line arguments (passed through to Spring)
    • blockchainNode

      @Bean public BlockchainNode 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

      @Bean public Wallet demoWallet()
      Provides a freshly generated demo wallet for signing REST-submitted transactions.

      The wallet's private key is generated at startup using WalletManager and is never persisted or logged (NFR-SEC-01). The wallet's address is printed to the application log at INFO level 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 Jackson ObjectMapper so that java.time.Instant fields serialize as ISO-8601 strings (e.g. "2026-06-06T10:00:00Z") instead of numeric timestamp arrays.

      Spring Boot 4 removed the Jackson2ObjectMapperBuilderCustomizer infrastructure. Declaring an ObjectMapper bean directly is the supported replacement and gives full control over serialization behavior.

      This matches the format produced by BlockSerializer.MAPPER used internally by all storage backends, keeping REST output consistent with persisted JSON payloads.

      Returns:
      a fully configured ObjectMapper