├── Chapter_01 └── knight │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ ├── java │ │ └── sia │ │ │ └── knights │ │ │ ├── BraveKnight.java │ │ │ ├── DamselRescuingKnight.java │ │ │ ├── Knight.java │ │ │ ├── KnightMain.java │ │ │ ├── Minstrel.java │ │ │ ├── Quest.java │ │ │ ├── RescueDamselQuest.java │ │ │ ├── SlayDragonQuest.java │ │ │ └── config │ │ │ ├── KnightConfig.java │ │ │ └── SoundSystemConfig.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ ├── knight.xml │ │ └── minstrel.xml │ ├── site │ └── site.xml │ └── test │ ├── java │ └── sia │ │ └── knights │ │ ├── BraveKnightTest.java │ │ ├── FakePrintStream.java │ │ ├── KnightConfig.java │ │ ├── KnightJavaConfigInjectionTest.java │ │ └── KnightXMLInjectionTest.java │ └── resources │ ├── log4j.properties │ └── sia │ └── knights │ └── KnightXMLInjectionTest-context.xml ├── Chapter_02 ├── README.md ├── stereo-autoconfig │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── java │ │ │ └── soundsystem │ │ │ │ ├── CDPlayer.java │ │ │ │ ├── CDPlayerConfig.java │ │ │ │ ├── CompactDisc.java │ │ │ │ ├── MediaPlayer.java │ │ │ │ └── SgtPeppers.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring │ │ │ └── soundsystem.xml │ │ ├── site │ │ └── site.xml │ │ └── test │ │ ├── java │ │ └── soundsystem │ │ │ ├── CDPlayerTest.java │ │ │ └── CDPlayerXMLConfigTest.java │ │ └── resources │ │ └── log4j.properties ├── stereo-javaconfig │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── java │ │ │ └── soundsystem │ │ │ │ ├── CDPlayer.java │ │ │ │ ├── CDPlayerConfig.java │ │ │ │ ├── CompactDisc.java │ │ │ │ ├── MediaPlayer.java │ │ │ │ └── SgtPeppers.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring │ │ │ └── app-context.xml │ │ ├── site │ │ └── site.xml │ │ └── test │ │ ├── java │ │ └── soundsystem │ │ │ └── CDPlayerTest.java │ │ └── resources │ │ └── log4j.properties ├── stereo-mixedconfig │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── java │ │ │ └── soundsystem │ │ │ │ ├── BlankDisc.java │ │ │ │ ├── CDConfig.java │ │ │ │ ├── CDPlayer.java │ │ │ │ ├── CDPlayerConfig.java │ │ │ │ ├── CompactDisc.java │ │ │ │ ├── MediaPlayer.java │ │ │ │ ├── SgtPeppers.java │ │ │ │ └── SoundSystemConfig.java │ │ └── resources │ │ │ ├── cd-config.xml │ │ │ └── cdplayer-config.xml │ │ ├── site │ │ └── site.xml │ │ └── test │ │ ├── java │ │ └── soundsystem │ │ │ ├── ImportJavaConfigTest.java │ │ │ └── ImportXmlConfigTest.java │ │ └── resources │ │ └── log4j.properties └── stereo-xmlconfig │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ └── java │ │ └── soundsystem │ │ ├── BlankDisc.java │ │ ├── CDPlayer.java │ │ ├── CDPlayerConfig.java │ │ ├── CompactDisc.java │ │ ├── MediaPlayer.java │ │ ├── SgtPeppers.java │ │ ├── collections │ │ └── BlankDisc.java │ │ └── properties │ │ ├── BlankDisc.java │ │ └── CDPlayer.java │ ├── site │ └── site.xml │ └── test │ ├── java │ └── soundsystem │ │ ├── CNamespaceReferenceTest.java │ │ ├── CNamespaceValueTest.java │ │ ├── ConstructorArgCollectionTest.java │ │ ├── ConstructorArgReferenceTest.java │ │ ├── ConstructorArgValueTest.java │ │ ├── PNamespaceRefTest.java │ │ ├── PNamespaceValueTest.java │ │ ├── PNamespaceWithUtilNamespaceTest.java │ │ ├── PropertyRefTest.java │ │ └── PropertyValueTest.java │ └── resources │ ├── log4j.properties │ └── soundsystem │ ├── CNamespaceReferenceTest-context.xml │ ├── CNamespaceValueTest-context.xml │ ├── ConstructorArgCollectionTest-context.xml │ ├── ConstructorArgReferenceTest-context.xml │ ├── ConstructorArgValueTest-context.xml │ ├── PNamespaceRefTest-context.xml │ ├── PNamespaceValueTest-context.xml │ ├── PNamespaceWithUtilNamespaceTest-context.xml │ ├── PropertyRefTest-context.xml │ └── PropertyValueTest-context.xml ├── Chapter_03 ├── README.md ├── conditional │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── habuma │ │ │ └── restfun │ │ │ ├── MagicBean.java │ │ │ ├── MagicConfig.java │ │ │ └── MagicExistsCondition.java │ │ └── test │ │ └── java │ │ └── com │ │ └── habuma │ │ └── restfun │ │ └── MagicExistsTest.java ├── externals │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── soundsystem │ │ │ │ └── BlankDisc.java │ │ └── resources │ │ │ └── com │ │ │ └── soundsystem │ │ │ └── app.properties │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── soundsystem │ │ │ ├── EnvironmentConfig.java │ │ │ ├── EnvironmentConfigWithDefaults.java │ │ │ ├── EnvironmentConfigWithRequiredProperties.java │ │ │ └── EnvironmentInjectionTest.java │ │ └── resources │ │ └── placeholder-config.xml ├── profiles │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── myapp │ │ │ │ └── DataSourceConfig.java │ │ └── resources │ │ │ ├── datasource-config.xml │ │ │ ├── schema.sql │ │ │ └── test-data.sql │ │ └── test │ │ └── java │ │ └── profiles │ │ └── DataSourceConfigTest.java └── scopedbeans │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── myapp │ │ │ ├── Notepad.java │ │ │ └── UniqueThing.java │ └── resources │ │ └── scoped-beans.xml │ └── test │ └── java │ └── com │ └── myapp │ ├── ComponentScannedConfig.java │ ├── ExplicitConfig.java │ └── ScopedBeanTests.java ├── Chapter_05 └── Spittr │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── Spitter.java │ │ │ ├── Spittle.java │ │ │ ├── config │ │ │ ├── DataConfig.java │ │ │ ├── RootConfig.java │ │ │ └── SpitterWebInitializer.java │ │ │ ├── data │ │ │ ├── JdbcSpitterRepository.java │ │ │ ├── JdbcSpittleRepository.java │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ │ │ └── web │ │ │ ├── HomeController.java │ │ │ ├── RegisterForm.java │ │ │ ├── SpitterController.java │ │ │ ├── SpittleController.java │ │ │ ├── SpittleForm.java │ │ │ └── WebConfig.java │ ├── resources │ │ ├── log4j.xml │ │ └── schema.sql │ └── webapp │ │ ├── WEB-INF │ │ ├── spring │ │ │ ├── appServlet │ │ │ │ └── servlet-context.xml │ │ │ └── root-context.xml │ │ └── views │ │ │ ├── home.jsp │ │ │ ├── profile.jsp │ │ │ ├── registerForm.jsp │ │ │ ├── spittle.jsp │ │ │ └── spittles.jsp │ │ └── resources │ │ └── style.css │ └── test │ ├── java │ └── spittr │ │ └── web │ │ ├── HomeControllerTest.java │ │ ├── SpitterControllerTest.java │ │ └── SpittleControllerTest.java │ └── resources │ └── log4j.xml ├── Chapter_06 ├── jsp │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── Spitter.java │ │ │ │ ├── Spittle.java │ │ │ │ ├── config │ │ │ │ ├── DataConfig.java │ │ │ │ ├── RootConfig.java │ │ │ │ └── SpitterWebInitializer.java │ │ │ │ ├── data │ │ │ │ ├── JdbcSpitterRepository.java │ │ │ │ ├── JdbcSpittleRepository.java │ │ │ │ ├── SpitterRepository.java │ │ │ │ └── SpittleRepository.java │ │ │ │ └── web │ │ │ │ ├── HomeController.java │ │ │ │ ├── SpitterController.java │ │ │ │ ├── SpittleController.java │ │ │ │ ├── SpittleForm.java │ │ │ │ └── WebConfig.java │ │ ├── resources │ │ │ ├── ValidationMessages.properties │ │ │ ├── ValidationMessages_es.properties │ │ │ ├── log4j.xml │ │ │ └── schema.sql │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── messages.properties │ │ │ ├── spring │ │ │ │ ├── appServlet │ │ │ │ │ └── servlet-context.xml │ │ │ │ └── root-context.xml │ │ │ └── views │ │ │ │ ├── home.jsp │ │ │ │ ├── profile.jsp │ │ │ │ ├── registerForm.jsp │ │ │ │ ├── spittle.jsp │ │ │ │ └── spittles.jsp │ │ │ └── resources │ │ │ └── style.css │ │ └── test │ │ ├── java │ │ └── spittr │ │ │ └── web │ │ │ ├── HomeControllerTest.java │ │ │ ├── SpitterControllerTest.java │ │ │ └── SpittleControllerTest.java │ │ └── resources │ │ └── log4j.xml ├── thymeleaf │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── Spitter.java │ │ │ │ ├── Spittle.java │ │ │ │ ├── config │ │ │ │ ├── DataConfig.java │ │ │ │ ├── RootConfig.java │ │ │ │ └── SpitterWebInitializer.java │ │ │ │ ├── data │ │ │ │ ├── JdbcSpitterRepository.java │ │ │ │ ├── JdbcSpittleRepository.java │ │ │ │ ├── SpitterRepository.java │ │ │ │ └── SpittleRepository.java │ │ │ │ └── web │ │ │ │ ├── HomeController.java │ │ │ │ ├── SpitterController.java │ │ │ │ ├── SpittleController.java │ │ │ │ ├── SpittleForm.java │ │ │ │ └── WebConfig.java │ │ ├── resources │ │ │ ├── ValidationMessages.properties │ │ │ ├── ValidationMessages_es.properties │ │ │ ├── log4j.xml │ │ │ └── schema.sql │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── .DS_Store │ │ │ ├── spring │ │ │ │ ├── appServlet │ │ │ │ │ └── servlet-context.xml │ │ │ │ └── root-context.xml │ │ │ └── views │ │ │ │ ├── home.html │ │ │ │ ├── page.html │ │ │ │ ├── profile.html │ │ │ │ ├── registerForm.html │ │ │ │ ├── spittle.html │ │ │ │ └── spittles.html │ │ │ └── resources │ │ │ ├── images │ │ │ ├── spitter_avatar.png │ │ │ ├── spitter_background.gif │ │ │ ├── spitter_logo_50.png │ │ │ └── spitter_me.jpg │ │ │ └── style.css │ │ └── test │ │ ├── java │ │ └── spitter │ │ │ └── web │ │ │ ├── HomeControllerTest.java │ │ │ ├── SpitterControllerTest.java │ │ │ └── SpittleControllerTest.java │ │ └── resources │ │ └── log4j.xml └── tiles │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── Spitter.java │ │ │ ├── Spittle.java │ │ │ ├── config │ │ │ ├── DataConfig.java │ │ │ ├── RootConfig.java │ │ │ └── SpitterWebInitializer.java │ │ │ ├── data │ │ │ ├── JdbcSpitterRepository.java │ │ │ ├── JdbcSpittleRepository.java │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ │ │ └── web │ │ │ ├── HomeController.java │ │ │ ├── SpitterController.java │ │ │ ├── SpittleController.java │ │ │ ├── SpittleForm.java │ │ │ └── WebConfig.java │ ├── resources │ │ ├── log4j.xml │ │ └── schema.sql │ └── webapp │ │ ├── WEB-INF │ │ ├── layout │ │ │ ├── footer.jsp │ │ │ ├── header.jsp │ │ │ ├── page.jsp │ │ │ └── tiles.xml │ │ ├── spring │ │ │ ├── appServlet │ │ │ │ └── servlet-context.xml │ │ │ └── root-context.xml │ │ └── views │ │ │ ├── home.jsp │ │ │ ├── profile.jsp │ │ │ ├── registerForm.jsp │ │ │ ├── spittle.jsp │ │ │ └── spittles.jsp │ │ └── resources │ │ ├── .DS_Store │ │ ├── images │ │ ├── spitter_avatar.png │ │ ├── spitter_background.gif │ │ ├── spitter_logo_50.png │ │ └── spitter_me.jpg │ │ └── style.css │ └── test │ ├── java │ └── spittr │ │ └── web │ │ ├── HomeControllerTest.java │ │ ├── SpitterControllerTest.java │ │ └── SpittleControllerTest.java │ └── resources │ └── log4j.xml ├── Chapter_07 └── Spittr │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── Spitter.java │ │ │ ├── Spittle.java │ │ │ ├── config │ │ │ ├── DataConfig.java │ │ │ ├── RootConfig.java │ │ │ └── SpitterWebInitializer.java │ │ │ ├── data │ │ │ ├── JdbcSpitterRepository.java │ │ │ ├── JdbcSpittleRepository.java │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ │ │ └── web │ │ │ ├── AppWideExceptionHandler.java │ │ │ ├── DuplicateSpittleException.java │ │ │ ├── FileUploadController.java │ │ │ ├── HomeController.java │ │ │ ├── SpitterController.java │ │ │ ├── SpitterForm.java │ │ │ ├── SpittleController.java │ │ │ ├── SpittleForm.java │ │ │ ├── SpittleNotFoundException.java │ │ │ └── WebConfig.java │ ├── resources │ │ ├── ValidationMessages.properties │ │ ├── ValidationMessages_es.properties │ │ ├── log4j.xml │ │ └── schema.sql │ └── webapp │ │ ├── WEB-INF │ │ ├── spring │ │ │ ├── appServlet │ │ │ │ └── servlet-context.xml │ │ │ └── root-context.xml │ │ └── views │ │ │ ├── home.html │ │ │ ├── page.html │ │ │ ├── profile.html │ │ │ ├── registerForm.html │ │ │ ├── spittle.html │ │ │ ├── spittles.html │ │ │ └── uploadForm.html │ │ └── resources │ │ ├── images │ │ ├── spitter_avatar.png │ │ ├── spitter_background.gif │ │ ├── spitter_logo_50.png │ │ └── spitter_me.jpg │ │ └── style.css │ └── test │ ├── java │ └── spittr │ │ └── web │ │ ├── HomeControllerTest.java │ │ ├── SpitterControllerTest.java │ │ └── SpittleControllerTest.java │ └── resources │ └── log4j.xml ├── Chapter_08 └── SpringPizza │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springinaction │ │ │ └── pizza │ │ │ ├── HomeController.java │ │ │ ├── PaymentException.java │ │ │ ├── domain │ │ │ ├── CashOrCheckPayment.java │ │ │ ├── CreditCardPayment.java │ │ │ ├── Customer.java │ │ │ ├── Order.java │ │ │ ├── Payment.java │ │ │ ├── PaymentDetails.java │ │ │ ├── PaymentType.java │ │ │ ├── Pizza.java │ │ │ ├── PizzaSize.java │ │ │ └── Topping.java │ │ │ ├── flow │ │ │ ├── PizzaFlowActions.java │ │ │ └── SpecialtyPizzaBuilder.java │ │ │ └── service │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── CustomerService.java │ │ │ ├── CustomerServiceImpl.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentProcessor.java │ │ │ ├── PricingEngine.java │ │ │ └── PricingEngineImpl.java │ ├── resources │ │ ├── log4j.properties │ │ ├── messages.properties │ │ └── scripts │ │ │ └── PricingEngineImpl.groovy │ └── webapp │ │ └── WEB-INF │ │ ├── flows │ │ ├── pizza-singleflow │ │ │ ├── createPizza.jsp │ │ │ ├── pizza-flow.xml │ │ │ ├── registrationForm.jsp │ │ │ ├── showOrder.jsp │ │ │ ├── takePayment.jsp │ │ │ ├── thankYou.jsp │ │ │ └── welcome.jsp │ │ └── pizza │ │ │ ├── customer │ │ │ ├── customer-flow.xml │ │ │ ├── deliveryWarning.jsp │ │ │ ├── registrationForm.jsp │ │ │ └── welcome.jsp │ │ │ ├── order │ │ │ ├── createPizza.jsp │ │ │ ├── order-flow.xml │ │ │ └── showOrder.jsp │ │ │ ├── payment │ │ │ ├── payment-flow.xml │ │ │ └── takePayment.jsp │ │ │ ├── pizza-flow.xml │ │ │ └── thankYou.jsp │ │ ├── oldjsps │ │ ├── chooseSize.jsp │ │ ├── chooseToppings.jsp │ │ ├── chooseType.jsp │ │ ├── creditCardForm.jsp │ │ ├── deliveryWarning.jsp │ │ ├── hello.jsp │ │ ├── home.jsp │ │ ├── newCustomerForm.jsp │ │ ├── newPizzaForm.jsp │ │ ├── orderDetails.jsp │ │ ├── paymentForm.jsp │ │ ├── paymentType.jsp │ │ └── phoneNumberForm.jsp │ │ ├── spring │ │ ├── dataaccess.xml │ │ ├── domain.xml │ │ ├── flow.xml │ │ ├── mvc.xml │ │ ├── root-config.xml │ │ └── services.xml │ │ └── web.xml │ └── test │ └── java │ └── com │ └── springinaction │ └── pizza │ └── flow │ └── PizzaFlowTest.java ├── Chapter_09 └── thymeleaf │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── Spitter.java │ │ │ ├── Spittle.java │ │ │ ├── config │ │ │ ├── DataConfig.java │ │ │ ├── MethodSecurityConfig.java │ │ │ ├── RootConfig.java │ │ │ ├── SecurityConfig.java │ │ │ ├── SecurityWebInitializer.java │ │ │ └── SpitterWebInitializer.java │ │ │ ├── data │ │ │ ├── JdbcSpitterRepository.java │ │ │ ├── JdbcSpittleRepository.java │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ │ │ └── web │ │ │ ├── HomeController.java │ │ │ ├── SpitterController.java │ │ │ ├── SpittleController.java │ │ │ ├── SpittleForm.java │ │ │ └── WebConfig.java │ ├── resources │ │ ├── ValidationMessages.properties │ │ ├── ValidationMessages_es.properties │ │ ├── log4j.xml │ │ └── schema.sql │ └── webapp │ │ ├── WEB-INF │ │ ├── .DS_Store │ │ ├── spring │ │ │ ├── appServlet │ │ │ │ └── servlet-context.xml │ │ │ └── root-context.xml │ │ ├── views │ │ │ ├── home.html │ │ │ ├── login.html │ │ │ ├── page.html │ │ │ ├── profile.html │ │ │ ├── registerForm.html │ │ │ ├── spittle.html │ │ │ └── spittles.html │ │ └── web.xml_not_used │ │ └── resources │ │ ├── images │ │ ├── spitter_avatar.png │ │ ├── spitter_background.gif │ │ ├── spitter_logo_50.png │ │ └── spitter_me.jpg │ │ └── style.css │ └── test │ ├── java │ └── spittr │ │ └── web │ │ ├── HomeControllerTest.java │ │ ├── SpitterControllerTest.java │ │ └── SpittleControllerTest.java │ └── resources │ └── log4j.xml ├── Chapter_10 └── jdbc │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── db │ │ │ ├── SpitterRepository.java │ │ │ ├── SpittleRepository.java │ │ │ └── jdbc │ │ │ │ ├── JdbcSpitterRepository.java │ │ │ │ └── JdbcSpittleRepository.java │ │ │ └── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ └── resources │ │ └── spittr │ │ └── db │ │ └── jdbc │ │ └── schema.sql │ └── test │ ├── java │ └── spittr │ │ └── jdbc │ │ ├── JdbcConfig.java │ │ ├── JdbcSpitterRepositoryTest.java │ │ └── JdbcSpittleRepositoryTest.java │ └── resources │ ├── log4j.properties │ └── spittr │ └── db │ └── jdbc │ ├── JdbcRepositoryTests-context.xml │ └── test-data.sql ├── Chapter_11 ├── hibernate4 │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── db │ │ │ │ ├── SpitterRepository.java │ │ │ │ ├── SpittleRepository.java │ │ │ │ └── hibernate4 │ │ │ │ │ ├── HibernateSpitterRepository.java │ │ │ │ │ └── HibernateSpittleRepository.java │ │ │ │ └── domain │ │ │ │ ├── Spitter.java │ │ │ │ └── Spittle.java │ │ └── resources │ │ │ └── spittr │ │ │ └── db │ │ │ └── hibernate4 │ │ │ └── schema.sql │ │ ├── site │ │ └── site.xml │ │ └── test │ │ ├── java │ │ └── spittr │ │ │ └── db │ │ │ └── hibernate4 │ │ │ ├── RepositoryTestConfig.java │ │ │ ├── SpitterRepositoryTest.java │ │ │ └── SpittleRepositoryTest.java │ │ └── resources │ │ ├── log4j.properties │ │ └── spittr │ │ └── db │ │ └── hibernate4 │ │ ├── RepositoryTest-context.xml │ │ └── test-data.sql ├── jpa-hibernate │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── db │ │ │ │ ├── SpitterRepository.java │ │ │ │ ├── SpittleRepository.java │ │ │ │ └── jpa │ │ │ │ │ ├── JpaSpitterRepository.java │ │ │ │ │ └── JpaSpittleRepository.java │ │ │ │ └── domain │ │ │ │ ├── Spitter.java │ │ │ │ └── Spittle.java │ │ └── resources │ │ │ └── spittr │ │ │ └── db │ │ │ └── jpa │ │ │ └── schema.sql │ │ ├── site │ │ └── site.xml │ │ └── test │ │ ├── java │ │ └── spittr │ │ │ └── db │ │ │ └── jpa │ │ │ ├── JpaConfig.java │ │ │ ├── SpitterRepositoryTest.java │ │ │ └── SpittleRepositoryTest.java │ │ └── resources │ │ ├── log4j.properties │ │ └── spittr │ │ └── db │ │ └── jpa │ │ ├── RepositoryTest-context.xml │ │ └── test-data.sql └── jpa-springdata │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── db │ │ │ ├── SpitterRepository.java │ │ │ ├── SpitterRepositoryImpl.java │ │ │ ├── SpitterSweeper.java │ │ │ ├── SpittleRepository.java │ │ │ ├── SpittleRepositoryCustom.java │ │ │ ├── SpittleRepositoryImpl.java │ │ │ └── SpringDataJpaConfig.java │ │ │ └── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ └── resources │ │ └── spittr │ │ └── db │ │ └── jpa │ │ └── schema.sql │ └── test │ ├── java │ └── spittr │ │ └── db │ │ └── jpa │ │ ├── JpaConfig.java │ │ ├── SpitterRepositoryTest.java │ │ └── SpittleRepositoryTest.java │ └── resources │ ├── log4j.properties │ └── spittr │ └── db │ └── jpa │ ├── RepositoryTest-context.xml │ └── test-data.sql ├── Chapter_12 ├── gradle.properties ├── mongo │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── java │ │ │ └── orders │ │ │ ├── Item.java │ │ │ ├── Order.java │ │ │ ├── config │ │ │ └── MongoConfig.java │ │ │ └── db │ │ │ └── OrderRepository.java │ │ └── test │ │ ├── java │ │ └── orders │ │ │ └── MongoDbTest.java │ │ └── resources │ │ └── log4j.properties ├── neo4j │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── java │ │ │ └── orders │ │ │ ├── Item.java │ │ │ ├── Order.java │ │ │ ├── config │ │ │ └── Neo4jConfig.java │ │ │ └── db │ │ │ └── OrderRepository.java │ │ └── test │ │ ├── java │ │ └── orders │ │ │ └── Neo4jTest.java │ │ └── resources │ │ └── log4j.properties └── redis │ ├── .gitignore │ ├── README │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ └── java │ │ └── cart │ │ ├── Product.java │ │ └── RedisConfig.java │ └── test │ └── java │ └── cart │ └── CartTest.java ├── Chapter_13 └── caching │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── config │ │ │ ├── CachingConfig.java │ │ │ ├── DataConfig.java │ │ │ └── RootConfig.java │ │ │ ├── db │ │ │ ├── SpitterRepository.java │ │ │ ├── SpittleRepository.java │ │ │ └── jdbc │ │ │ │ ├── JdbcSpitterRepository.java │ │ │ │ └── JdbcSpittleRepository.java │ │ │ └── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ └── resources │ │ └── spittr │ │ ├── cache │ │ └── ehcache.xml │ │ └── db │ │ └── jdbc │ │ └── schema.sql │ ├── site │ └── site.xml │ └── test │ ├── java │ └── spittr │ │ └── db │ │ └── jdbc │ │ ├── JdbcSpitterRepositoryTest.java │ │ └── JdbcSpittleRepositoryTest.java │ └── resources │ ├── log4j.properties │ └── spittr │ └── db │ └── jdbc │ └── test-data.sql ├── Chapter_14 └── methodsecurity │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── config │ │ │ ├── ExpressionSecurityConfig.java │ │ │ ├── JSR250Config.java │ │ │ └── SecuredConfig.java │ │ │ ├── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ │ │ └── service │ │ │ ├── ExpressionSecuredSpittleService.java │ │ │ ├── JSR250SpittleService.java │ │ │ ├── SecuredSpittleService.java │ │ │ └── SpittleService.java │ └── resources │ │ └── collateral │ │ └── coupon.jpg │ └── test │ └── java │ └── spittr │ └── service │ ├── ExpressionSecuredSpittrServiceSecurityTest.java │ ├── JSR250SpittrServiceSecurityTest.java │ └── SecuredSpittrServiceSecurityTest.java ├── Chapter_16 ├── spitter-api-content-negotiation │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── Spitter.java │ │ │ │ ├── Spittle.java │ │ │ │ ├── api │ │ │ │ └── SpittleApiController.java │ │ │ │ ├── config │ │ │ │ ├── DataConfig.java │ │ │ │ ├── RootConfig.java │ │ │ │ └── SpitterWebInitializer.java │ │ │ │ ├── data │ │ │ │ ├── JdbcSpitterRepository.java │ │ │ │ ├── JdbcSpittleRepository.java │ │ │ │ ├── SpitterRepository.java │ │ │ │ └── SpittleRepository.java │ │ │ │ └── web │ │ │ │ ├── HomeController.java │ │ │ │ ├── RegisterForm.java │ │ │ │ ├── SpitterController.java │ │ │ │ ├── SpittleController.java │ │ │ │ ├── SpittleForm.java │ │ │ │ └── WebConfig.java │ │ ├── resources │ │ │ ├── log4j.xml │ │ │ └── schema.sql │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── spring │ │ │ │ ├── appServlet │ │ │ │ │ └── servlet-context.xml │ │ │ │ └── root-context.xml │ │ │ └── views │ │ │ │ ├── home.jsp │ │ │ │ ├── profile.jsp │ │ │ │ ├── registerForm.jsp │ │ │ │ ├── spittle.jsp │ │ │ │ └── spittles.jsp │ │ │ └── resources │ │ │ └── style.css │ │ └── test │ │ ├── java │ │ └── spittr │ │ │ └── web │ │ │ ├── HomeControllerTest.java │ │ │ ├── SpitterControllerTest.java │ │ │ └── SpittleControllerTest.java │ │ └── resources │ │ └── log4j.xml └── spitter-api-message-converters │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ ├── src │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── Spitter.java │ │ │ │ ├── Spittle.java │ │ │ │ ├── api │ │ │ │ ├── Error.java │ │ │ │ └── SpittleApiController.java │ │ │ │ ├── config │ │ │ │ ├── DataConfig.java │ │ │ │ ├── RootConfig.java │ │ │ │ └── SpitterWebInitializer.java │ │ │ │ ├── data │ │ │ │ ├── JdbcSpittleRepository.java │ │ │ │ ├── SpittleNotFoundException.java │ │ │ │ └── SpittleRepository.java │ │ │ │ └── web │ │ │ │ └── WebConfig.java │ │ ├── resources │ │ │ ├── log4j.xml │ │ │ └── schema.sql │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── spring │ │ │ │ ├── appServlet │ │ │ │ │ └── servlet-context.xml │ │ │ │ └── root-context.xml │ │ │ └── views │ │ │ │ ├── home.jsp │ │ │ │ ├── profile.jsp │ │ │ │ ├── registerForm.jsp │ │ │ │ ├── spittle.jsp │ │ │ │ └── spittles.jsp │ │ │ └── resources │ │ │ └── style.css │ └── test │ │ └── resources │ │ └── log4j.xml │ └── testdata.json ├── Chapter_17 ├── amqp │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── alerts │ │ │ │ ├── AlertService.java │ │ │ │ ├── AlertServiceImpl.java │ │ │ │ └── SpittleAlertHandler.java │ │ │ │ ├── domain │ │ │ │ ├── Spitter.java │ │ │ │ └── Spittle.java │ │ │ │ └── message │ │ │ │ ├── ConsumerMain.java │ │ │ │ └── ProducerMain.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring │ │ │ ├── amqp-consumer.xml │ │ │ ├── amqp-producer.xml │ │ │ └── amqp-shared.xml │ │ ├── site │ │ └── site.xml │ │ └── test │ │ └── resources │ │ └── log4j.properties └── jms │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── JMSMain.java │ │ │ ├── alerts │ │ │ ├── AlertService.java │ │ │ ├── AlertServiceImpl.java │ │ │ ├── SpittleAlertHandler.java │ │ │ └── SpittleJmsMain.java │ │ │ └── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ └── messaging.xml │ └── test │ └── resources │ └── log4j.properties ├── Chapter_18 ├── STOMP │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── java │ │ │ └── marcopolo │ │ │ │ ├── MarcoController.java │ │ │ │ ├── RandomNumberMessageSender.java │ │ │ │ ├── Shout.java │ │ │ │ ├── WebConfig.java │ │ │ │ ├── WebInitializer.java │ │ │ │ └── WebSocketStompConfig.java │ │ ├── resources │ │ │ ├── log4j.xml │ │ │ └── websocket-config.xml │ │ └── webapp │ │ │ └── WEB-INF │ │ │ └── views │ │ │ └── home.html │ │ └── test │ │ └── resources │ │ └── log4j.xml ├── STOMPUser │ ├── .gitignore │ ├── README │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── java │ │ │ └── spittr │ │ │ │ ├── NaiveMapBasedSpittleRepository.java │ │ │ │ ├── Notification.java │ │ │ │ ├── SecurityConfig.java │ │ │ │ ├── SecurityWebInitializer.java │ │ │ │ ├── Spittle.java │ │ │ │ ├── SpittleFeedService.java │ │ │ │ ├── SpittleFeedServiceImpl.java │ │ │ │ ├── SpittleForm.java │ │ │ │ ├── SpittleRepository.java │ │ │ │ ├── SpittrMessageController.java │ │ │ │ ├── WebConfig.java │ │ │ │ ├── WebInitializer.java │ │ │ │ └── WebSocketStompConfig.java │ │ ├── resources │ │ │ └── log4j.xml │ │ └── webapp │ │ │ └── WEB-INF │ │ │ └── views │ │ │ └── home.html │ │ └── test │ │ └── resources │ │ └── log4j.xml └── WebSocket │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ ├── java │ │ └── marcopolo │ │ │ ├── MarcoHandler.java │ │ │ ├── Shout.java │ │ │ ├── WebConfig.java │ │ │ ├── WebInitializer.java │ │ │ └── WebSocketConfig.java │ ├── resources │ │ ├── log4j.xml │ │ └── websocket-config.xml │ └── webapp │ │ └── WEB-INF │ │ └── views │ │ └── home.html │ └── test │ └── resources │ └── log4j.xml ├── Chapter_19 └── mail │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── config │ │ │ └── MailConfig.java │ │ │ ├── domain │ │ │ ├── Spitter.java │ │ │ └── Spittle.java │ │ │ └── email │ │ │ ├── SpitterMailService.java │ │ │ └── SpitterMailServiceImpl.java │ └── resources │ │ └── collateral │ │ └── coupon.jpg │ └── test │ ├── java │ └── spittr │ │ └── email │ │ └── SpitterMailServiceImplTest.java │ └── resources │ └── mail.properties ├── Chapter_21 ├── contacts │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── contacts │ │ │ ├── Application.java │ │ │ ├── Contact.java │ │ │ ├── ContactController.java │ │ │ └── ContactRepository.java │ │ └── resources │ │ ├── public │ │ └── style.css │ │ ├── schema.sql │ │ └── templates │ │ └── home.html ├── contacts_cli │ ├── .gitignore │ ├── Contact.groovy │ ├── ContactController.groovy │ ├── ContactRepository.groovy │ ├── schema.sql │ ├── static │ │ └── style.css │ └── templates │ │ └── home.html └── rest_hi │ ├── .gitignore │ └── Hi.groovy ├── README.md └── gradle.properties /Chapter_01/knight/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build 5 | bin 6 | .classpath 7 | .project 8 | .settings 9 | .springBeans 10 | exploration 11 | *.iml 12 | *.ipr 13 | *.iws 14 | -------------------------------------------------------------------------------- /Chapter_01/knight/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'knight' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | compile("org.aspectj:aspectjweaver:${aspectJVersion}") 18 | compile("log4j:log4j:${log4jVersion}") 19 | 20 | testCompile("junit:junit:${junitVersion}") 21 | testCompile("org.mockito:mockito-core:${mockitoVersion}") 22 | testCompile("org.springframework:spring-test:${springVersion}") 23 | } 24 | 25 | task wrapper(type: Wrapper) { 26 | gradleVersion = '1.11' 27 | } -------------------------------------------------------------------------------- /Chapter_01/knight/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_01/knight/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_01/knight/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 29 19:17:43 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/BraveKnight.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public class BraveKnight implements Knight { 4 | 5 | private Quest quest; 6 | 7 | public BraveKnight(Quest quest) { 8 | this.quest = quest; 9 | } 10 | 11 | public void embarkOnQuest() { 12 | quest.embark(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/DamselRescuingKnight.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public class DamselRescuingKnight implements Knight { 4 | 5 | private RescueDamselQuest quest; 6 | 7 | public DamselRescuingKnight() { 8 | this.quest = new RescueDamselQuest(); 9 | } 10 | 11 | public void embarkOnQuest() { 12 | quest.embark(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/Knight.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public interface Knight { 4 | 5 | void embarkOnQuest(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/KnightMain.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import org.springframework.context.support. 4 | ClassPathXmlApplicationContext; 5 | 6 | public class KnightMain { 7 | 8 | public static void main(String[] args) throws Exception { 9 | ClassPathXmlApplicationContext context = 10 | new ClassPathXmlApplicationContext( 11 | "META-INF/spring/knight.xml"); 12 | Knight knight = context.getBean(Knight.class); 13 | knight.embarkOnQuest(); 14 | context.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/Minstrel.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class Minstrel { 6 | 7 | private PrintStream stream; 8 | 9 | public Minstrel(PrintStream stream) { 10 | this.stream = stream; 11 | } 12 | 13 | public void singBeforeQuest() { 14 | stream.println("Fa la la, the knight is so brave!"); 15 | } 16 | 17 | public void singAfterQuest() { 18 | stream.println("Tee hee hee, the brave knight " + 19 | "did embark on a quest!"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/Quest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public interface Quest { 4 | 5 | void embark(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/RescueDamselQuest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public class RescueDamselQuest implements Quest { 4 | 5 | public void embark() { 6 | System.out.println("Embarking on a quest to rescue the damsel."); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/SlayDragonQuest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class SlayDragonQuest implements Quest { 6 | 7 | private PrintStream stream; 8 | 9 | public SlayDragonQuest(PrintStream stream) { 10 | this.stream = stream; 11 | } 12 | 13 | public void embark() { 14 | stream.println("Embarking on quest to slay the dragon!"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/config/KnightConfig.java: -------------------------------------------------------------------------------- 1 | package sia.knights.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import sia.knights.BraveKnight; 7 | import sia.knights.Knight; 8 | import sia.knights.Quest; 9 | import sia.knights.SlayDragonQuest; 10 | 11 | @Configuration 12 | public class KnightConfig { 13 | 14 | @Bean 15 | public Knight knight() { 16 | return new BraveKnight(quest()); 17 | } 18 | 19 | @Bean 20 | public Quest quest() { 21 | return new SlayDragonQuest(System.out); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/java/sia/knights/config/SoundSystemConfig.java: -------------------------------------------------------------------------------- 1 | package sia.knights.config; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.ComponentScan.Filter; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @ComponentScan(basePackages = "com.habuma.soundsystem", 9 | excludeFilters = { @Filter(Configuration.class) }) 10 | public class SoundSystemConfig { 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/main/resources/META-INF/spring/knight.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/test/java/sia/knights/BraveKnightTest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | import static org.mockito.Mockito.*; 3 | 4 | import org.junit.Test; 5 | 6 | import sia.knights.BraveKnight; 7 | import sia.knights.Quest; 8 | 9 | public class BraveKnightTest { 10 | 11 | @Test 12 | public void knightShouldEmbarkOnQuest() { 13 | Quest mockQuest = mock(Quest.class); 14 | BraveKnight knight = new BraveKnight(mockQuest); 15 | knight.embarkOnQuest(); 16 | verify(mockQuest, times(1)).embark(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/test/java/sia/knights/FakePrintStream.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.PrintStream; 5 | 6 | public class FakePrintStream extends PrintStream { 7 | 8 | private static StringBuffer printBuffer = new StringBuffer(); 9 | 10 | 11 | public FakePrintStream() { 12 | super(new ByteArrayOutputStream()); 13 | } 14 | 15 | @Override 16 | public void println(String string) { 17 | printBuffer.append(string).append("\n"); 18 | } 19 | 20 | public String getPrintedString() { 21 | return printBuffer.toString(); 22 | } 23 | 24 | public void clear() { 25 | printBuffer = new StringBuffer(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/test/java/sia/knights/KnightConfig.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import java.io.PrintStream; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import sia.knights.BraveKnight; 9 | import sia.knights.Knight; 10 | import sia.knights.Quest; 11 | import sia.knights.SlayDragonQuest; 12 | 13 | @Configuration 14 | public class KnightConfig { 15 | 16 | @Bean 17 | public Knight knight() { 18 | return new BraveKnight(quest()); 19 | } 20 | 21 | @Bean 22 | public Quest quest() { 23 | return new SlayDragonQuest(stream()); 24 | } 25 | 26 | @Bean 27 | public PrintStream stream() { 28 | return new FakePrintStream(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_01/knight/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build 5 | bin 6 | .classpath 7 | .project 8 | .settings 9 | .springBeans 10 | exploration 11 | *.iml 12 | *.ipr 13 | *.iws 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'stereo-autoconfig' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile "org.springframework:spring-context:${springVersion}" 17 | 18 | testCompile "org.springframework:spring-test:${springVersion}" 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_02/stereo-autoconfig/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 30 09:08:48 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/java/soundsystem/CDPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class CDPlayer implements MediaPlayer { 7 | private CompactDisc cd; 8 | 9 | @Autowired 10 | public CDPlayer(CompactDisc cd) { 11 | this.cd = cd; 12 | } 13 | 14 | public void play() { 15 | cd.play(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/java/soundsystem/CDPlayerConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.context.annotation.ComponentScan; 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | @ComponentScan 7 | public class CDPlayerConfig { 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/java/soundsystem/CompactDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface CompactDisc { 4 | void play(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/java/soundsystem/MediaPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface MediaPlayer { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/java/soundsystem/SgtPeppers.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.stereotype.Component; 3 | 4 | @Component 5 | public class SgtPeppers implements CompactDisc { 6 | 7 | private String title = "Sgt. Pepper's Lonely Hearts Club Band"; 8 | private String artist = "The Beatles"; 9 | 10 | public void play() { 11 | System.out.println("Playing " + title + " by " + artist); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/main/resources/META-INF/spring/soundsystem.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_02/stereo-autoconfig/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build 5 | bin 6 | .classpath 7 | .project 8 | .settings 9 | .springBeans 10 | exploration 11 | *.iml 12 | *.ipr 13 | *.iws 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'stereo-javaconfig' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_02/stereo-javaconfig/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 30 09:05:39 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/java/soundsystem/CDPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | public class CDPlayer implements MediaPlayer { 5 | private CompactDisc cd; 6 | 7 | @Autowired 8 | public CDPlayer(CompactDisc cd) { 9 | this.cd = cd; 10 | } 11 | 12 | public void play() { 13 | cd.play(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/java/soundsystem/CDPlayerConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.context.annotation.Bean; 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | public class CDPlayerConfig { 7 | 8 | @Bean 9 | public CompactDisc compactDisc() { 10 | return new SgtPeppers(); 11 | } 12 | 13 | @Bean 14 | public CDPlayer cdPlayer(CompactDisc compactDisc) { 15 | return new CDPlayer(compactDisc); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/java/soundsystem/CompactDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface CompactDisc { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/java/soundsystem/MediaPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface MediaPlayer { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/java/soundsystem/SgtPeppers.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | 4 | public class SgtPeppers implements CompactDisc { 5 | 6 | private String title = "Sgt. Pepper's Lonely Hearts Club Band"; 7 | private String artist = "The Beatles"; 8 | 9 | public void play() { 10 | System.out.println("Playing " + title + " by " + artist); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/main/resources/META-INF/spring/app-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_02/stereo-javaconfig/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build 5 | bin 6 | .classpath 7 | .project 8 | .settings 9 | .springBeans 10 | exploration 11 | *.iml 12 | *.ipr 13 | *.iws 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'stereo-mixedconfig' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '2.1' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_02/stereo-mixedconfig/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 30 09:05:39 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/BlankDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | import java.util.List; 4 | 5 | public class BlankDisc implements CompactDisc { 6 | 7 | private String title; 8 | private String artist; 9 | private List tracks; 10 | 11 | public BlankDisc(String title, String artist, List tracks) { 12 | this.title = title; 13 | this.artist = artist; 14 | this.tracks = tracks; 15 | } 16 | 17 | public void play() { 18 | System.out.println("Playing " + title + " by " + artist); 19 | for (String track : tracks) { 20 | System.out.println("-Track: " + track); 21 | } 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/CDConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | public class CDConfig { 8 | @Bean 9 | public CompactDisc compactDisc() { 10 | return new SgtPeppers(); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/CDPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | public class CDPlayer implements MediaPlayer { 5 | private CompactDisc cd; 6 | 7 | @Autowired 8 | public CDPlayer(CompactDisc cd) { 9 | this.cd = cd; 10 | } 11 | 12 | public void play() { 13 | cd.play(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/CDPlayerConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.context.annotation.Bean; 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | public class CDPlayerConfig { 7 | 8 | @Bean 9 | public CDPlayer cdPlayer(CompactDisc compactDisc) { 10 | return new CDPlayer(compactDisc); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/CompactDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface CompactDisc { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/MediaPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface MediaPlayer { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/SgtPeppers.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | 4 | public class SgtPeppers implements CompactDisc { 5 | 6 | private String title = "Sgt. Pepper's Lonely Hearts Club Band"; 7 | private String artist = "The Beatles"; 8 | 9 | public void play() { 10 | System.out.println("Playing " + title + " by " + artist); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/java/soundsystem/SoundSystemConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.context.annotation.Import; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | @Configuration 8 | @Import(CDPlayerConfig.class) 9 | @ImportResource("classpath:cd-config.xml") 10 | public class SoundSystemConfig { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/main/resources/cdplayer-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_02/stereo-mixedconfig/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build 5 | bin 6 | .classpath 7 | .project 8 | .settings 9 | .springBeans 10 | exploration 11 | *.iml 12 | *.ipr 13 | *.iws 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'stereo-xmlconfig' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_02/stereo-xmlconfig/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 29 20:01:25 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/BlankDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public class BlankDisc implements CompactDisc { 4 | 5 | private String title; 6 | private String artist; 7 | 8 | public BlankDisc(String title, String artist) { 9 | this.title = title; 10 | this.artist = artist; 11 | } 12 | 13 | public void play() { 14 | System.out.println("Playing " + title + " by " + artist); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/CDPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | public class CDPlayer implements MediaPlayer { 5 | private CompactDisc cd; 6 | 7 | @Autowired 8 | public CDPlayer(CompactDisc cd) { 9 | this.cd = cd; 10 | } 11 | 12 | public void play() { 13 | cd.play(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/CDPlayerConfig.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | import org.springframework.context.annotation.Bean; 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | public class CDPlayerConfig { 7 | 8 | @Bean 9 | public CompactDisc compactDisc() { 10 | return new SgtPeppers(); 11 | } 12 | 13 | @Bean 14 | public CDPlayer cdPlayer() { 15 | return new CDPlayer(compactDisc()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/CompactDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface CompactDisc { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/MediaPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public interface MediaPlayer { 4 | 5 | void play(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/SgtPeppers.java: -------------------------------------------------------------------------------- 1 | package soundsystem; 2 | 3 | public class SgtPeppers implements CompactDisc { 4 | 5 | private String title = "Sgt. Pepper's Lonely Hearts Club Band"; 6 | private String artist = "The Beatles"; 7 | 8 | public void play() { 9 | System.out.println("Playing " + title + " by " + artist); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/collections/BlankDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem.collections; 2 | 3 | import java.util.List; 4 | 5 | import soundsystem.CompactDisc; 6 | 7 | public class BlankDisc implements CompactDisc { 8 | 9 | private String title; 10 | private String artist; 11 | private List tracks; 12 | 13 | public BlankDisc(String title, String artist, List tracks) { 14 | this.title = title; 15 | this.artist = artist; 16 | this.tracks = tracks; 17 | } 18 | 19 | public void play() { 20 | System.out.println("Playing " + title + " by " + artist); 21 | for (String track : tracks) { 22 | System.out.println("-Track: " + track); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/properties/BlankDisc.java: -------------------------------------------------------------------------------- 1 | package soundsystem.properties; 2 | 3 | import java.util.List; 4 | 5 | import soundsystem.CompactDisc; 6 | 7 | public class BlankDisc implements CompactDisc { 8 | 9 | private String title; 10 | private String artist; 11 | private List tracks; 12 | 13 | public void setTitle(String title) { 14 | this.title = title; 15 | } 16 | 17 | public void setArtist(String artist) { 18 | this.artist = artist; 19 | } 20 | 21 | public void setTracks(List tracks) { 22 | this.tracks = tracks; 23 | } 24 | 25 | public void play() { 26 | System.out.println("Playing " + title + " by " + artist); 27 | for (String track : tracks) { 28 | System.out.println("-Track: " + track); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/main/java/soundsystem/properties/CDPlayer.java: -------------------------------------------------------------------------------- 1 | package soundsystem.properties; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | import soundsystem.CompactDisc; 5 | import soundsystem.MediaPlayer; 6 | 7 | public class CDPlayer implements MediaPlayer { 8 | private CompactDisc compactDisc; 9 | 10 | @Autowired 11 | public void setCompactDisc(CompactDisc compactDisc) { 12 | this.compactDisc = compactDisc; 13 | } 14 | 15 | public void play() { 16 | compactDisc.play(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/CNamespaceReferenceTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/CNamespaceValueTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/ConstructorArgReferenceTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/ConstructorArgValueTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/PNamespaceRefTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_02/stereo-xmlconfig/src/test/resources/soundsystem/PropertyRefTest-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_03/conditional/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | -------------------------------------------------------------------------------- /Chapter_03/conditional/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'conditional' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_03/conditional/src/main/java/com/habuma/restfun/MagicBean.java: -------------------------------------------------------------------------------- 1 | package com.habuma.restfun; 2 | 3 | public class MagicBean { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /Chapter_03/conditional/src/main/java/com/habuma/restfun/MagicConfig.java: -------------------------------------------------------------------------------- 1 | package com.habuma.restfun; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Conditional; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class MagicConfig { 9 | 10 | @Bean 11 | @Conditional(MagicExistsCondition.class) 12 | public MagicBean magicBean() { 13 | return new MagicBean(); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Chapter_03/conditional/src/main/java/com/habuma/restfun/MagicExistsCondition.java: -------------------------------------------------------------------------------- 1 | package com.habuma.restfun; 2 | 3 | import org.springframework.context.annotation.Condition; 4 | import org.springframework.context.annotation.ConditionContext; 5 | import org.springframework.core.env.Environment; 6 | import org.springframework.core.type.AnnotatedTypeMetadata; 7 | 8 | public class MagicExistsCondition implements Condition { 9 | 10 | @Override 11 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { 12 | Environment env = context.getEnvironment(); 13 | return env.containsProperty("magic"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_03/externals/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .settings 4 | .springBeans 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_03/externals/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'externals' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_03/externals/src/main/java/com/soundsystem/BlankDisc.java: -------------------------------------------------------------------------------- 1 | package com.soundsystem; 2 | 3 | 4 | public class BlankDisc { 5 | 6 | private final String title; 7 | private final String artist; 8 | 9 | public BlankDisc(String title, String artist) { 10 | this.title = title; 11 | this.artist = artist; 12 | } 13 | 14 | public String getTitle() { 15 | return title; 16 | } 17 | 18 | public String getArtist() { 19 | return artist; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_03/externals/src/main/resources/com/soundsystem/app.properties: -------------------------------------------------------------------------------- 1 | disc.title=Sgt. Peppers Lonely Hearts Club Band 2 | disc.artist=The Beatles -------------------------------------------------------------------------------- /Chapter_03/externals/src/test/java/com/soundsystem/EnvironmentConfig.java: -------------------------------------------------------------------------------- 1 | package com.soundsystem; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.PropertySource; 7 | import org.springframework.core.env.Environment; 8 | 9 | @Configuration 10 | @PropertySource("classpath:/com/soundsystem/app.properties") 11 | public class EnvironmentConfig { 12 | 13 | @Autowired 14 | Environment env; 15 | 16 | @Bean 17 | public BlankDisc blankDisc() { 18 | return new BlankDisc( 19 | env.getProperty("disc.title"), 20 | env.getProperty("disc.artist")); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_03/externals/src/test/java/com/soundsystem/EnvironmentConfigWithDefaults.java: -------------------------------------------------------------------------------- 1 | package com.soundsystem; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.env.Environment; 7 | 8 | @Configuration 9 | public class EnvironmentConfigWithDefaults { 10 | 11 | @Autowired 12 | Environment env; 13 | 14 | @Bean 15 | public BlankDisc blankDisc() { 16 | return new BlankDisc( 17 | env.getProperty("disc.title", "Rattle and Hum"), 18 | env.getProperty("disc.artist", "U2")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_03/externals/src/test/java/com/soundsystem/EnvironmentConfigWithRequiredProperties.java: -------------------------------------------------------------------------------- 1 | package com.soundsystem; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.env.Environment; 7 | 8 | @Configuration 9 | public class EnvironmentConfigWithRequiredProperties { 10 | 11 | @Autowired 12 | Environment env; 13 | 14 | @Bean 15 | public BlankDisc blankDisc() { 16 | return new BlankDisc( 17 | env.getRequiredProperty("disc.title"), 18 | env.getRequiredProperty("disc.artist")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_03/externals/src/test/resources/placeholder-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_03/profiles/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | -------------------------------------------------------------------------------- /Chapter_03/profiles/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'profiles' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | compile("org.springframework:spring-jdbc:${springVersion}") 18 | compile("com.h2database:h2:${h2Version}") 19 | 20 | testCompile("org.springframework:spring-test:${springVersion}") 21 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 22 | } 23 | 24 | task wrapper(type: Wrapper) { 25 | gradleVersion = '1.11' 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_03/profiles/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Things ( 2 | id identity, 3 | name varchar(100) 4 | ); -------------------------------------------------------------------------------- /Chapter_03/profiles/src/main/resources/test-data.sql: -------------------------------------------------------------------------------- 1 | insert into Things (name) values ('A') -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .classpath 4 | .settings 5 | .project 6 | .springBeans 7 | .gradle -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | jar { 6 | baseName = 'scopedbeans' 7 | version = '0.0.1-SNAPSHOT' 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | compile("org.springframework:spring-context:${springVersion}") 17 | 18 | testCompile("org.springframework:spring-test:${springVersion}") 19 | testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}" 20 | } 21 | 22 | task wrapper(type: Wrapper) { 23 | gradleVersion = '1.11' 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/src/main/java/com/myapp/Notepad.java: -------------------------------------------------------------------------------- 1 | package com.myapp; 2 | 3 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) 9 | public class Notepad { 10 | // the details of this class are inconsequential to this example 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/src/main/java/com/myapp/UniqueThing.java: -------------------------------------------------------------------------------- 1 | package com.myapp; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class UniqueThing { 7 | // the details of this class are inconsequential to this example 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/src/main/resources/scoped-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/src/test/java/com/myapp/ComponentScannedConfig.java: -------------------------------------------------------------------------------- 1 | package com.myapp; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.ComponentScan.Filter; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.FilterType; 7 | 8 | @Configuration 9 | @ComponentScan(excludeFilters={@Filter(type=FilterType.ANNOTATION, value=Configuration.class)}) 10 | public class ComponentScannedConfig { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_03/scopedbeans/src/test/java/com/myapp/ExplicitConfig.java: -------------------------------------------------------------------------------- 1 | package com.myapp; 2 | 3 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Scope; 7 | 8 | @Configuration 9 | public class ExplicitConfig { 10 | 11 | @Bean 12 | @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) 13 | public Notepad notepad() { 14 | return new Notepad(); 15 | } 16 | 17 | @Bean 18 | public UniqueThing unique() { 19 | return new UniqueThing(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_05/Spittr/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_05/Spittr/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 24 23:19:26 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr' 2 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 9 | 10 | 11 |

Welcome to Spitter

12 | 13 | ">Spittles | 14 | ">Register 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/WEB-INF/views/profile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 7 | 8 | 9 |

Your Profile

10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/WEB-INF/views/registerForm.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 8 | 9 | 10 |

Register

11 | 12 |
13 | First Name:
14 | Last Name:
15 | Email:
16 | Username:
17 | Password:
18 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/WEB-INF/views/spittle.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Spitter 5 | " > 8 | 9 | 10 |
11 |
12 |
13 | 14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/main/webapp/resources/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .spittleList h1 { 6 | font-size: 16pt; 7 | } 8 | 9 | .spittleList ul { 10 | list-style: none; 11 | margin-left: 0px; 12 | padding-left: 0px; 13 | } 14 | 15 | .spittleList ul li:first-child { 16 | border-top: 0px; 17 | } 18 | 19 | .spittleList ul li { 20 | border-top: 1px solid #cccccc; 21 | } 22 | 23 | .spittleTime { 24 | font-size: 8pt; 25 | } 26 | 27 | .spittleLocation { 28 | font-size: 8pt; 29 | } 30 | 31 | .spittleForm h1 { 32 | font-size: 16pt; 33 | } -------------------------------------------------------------------------------- /Chapter_05/Spittr/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | import spittr.web.HomeController; 10 | 11 | public class HomeControllerTest { 12 | 13 | @Test 14 | public void testHomePage() throws Exception { 15 | HomeController controller = new HomeController(); 16 | MockMvc mockMvc = standaloneSetup(controller).build(); 17 | mockMvc.perform(get("/")) 18 | .andExpect(view().name("home")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_06/jsp/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_06/jsp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/jsp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_06/jsp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 02 17:41:00 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_06/jsp/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr-JSP' 2 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/resources/ValidationMessages.properties: -------------------------------------------------------------------------------- 1 | firstName.size=First name must be between {min} and {max} characters long. 2 | lastName.size=Last name must be between {min} and {max} characters long. 3 | username.size=Username must be between {min} and {max} characters long. 4 | password.size=Password must be between {min} and {max} characters long. 5 | email.valid=The email address must be valid. 6 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/jsp/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/WEB-INF/messages.properties: -------------------------------------------------------------------------------- 1 | spitter.welcome=Welcome to Spitter! -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %> 3 | <%@ page session="false" %> 4 | 5 | 6 | Spitter 7 | " > 10 | 11 | 12 |

13 | 14 | 15 | 16 | ">Spittles | 17 | Register 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/WEB-INF/views/profile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 7 | 8 | 9 |

Your Profile

10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/WEB-INF/views/spittle.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Spitter 5 | " > 8 | 9 | 10 |
11 |
12 |
13 | 14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_06/jsp/src/main/webapp/resources/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .spittleList h1 { 6 | font-size: 16pt; 7 | } 8 | 9 | .spittleList ul { 10 | list-style: none; 11 | margin-left: 0px; 12 | padding-left: 0px; 13 | } 14 | 15 | .spittleList ul li:first-child { 16 | border-top: 0px; 17 | } 18 | 19 | .spittleList ul li { 20 | border-top: 1px solid #cccccc; 21 | } 22 | 23 | .spittleTime { 24 | font-size: 8pt; 25 | } 26 | 27 | .spittleLocation { 28 | font-size: 8pt; 29 | } 30 | 31 | .spittleForm h1 { 32 | font-size: 16pt; 33 | } 34 | 35 | label.error { 36 | color: red; 37 | } 38 | 39 | input.error { 40 | background-color: #ffcccc; 41 | } 42 | 43 | div.errors { 44 | background-color: #ffcccc; 45 | border: 2px solid red; 46 | } -------------------------------------------------------------------------------- /Chapter_06/jsp/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | public class HomeControllerTest { 10 | 11 | @Test 12 | public void testHomePage() throws Exception { 13 | HomeController controller = new HomeController(); 14 | MockMvc mockMvc = standaloneSetup(controller).build(); 15 | mockMvc.perform(get("/")) 16 | .andExpect(view().name("home")); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 02 17:41:54 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr-Thymeleaf' 2 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/resources/ValidationMessages.properties: -------------------------------------------------------------------------------- 1 | firstName.size=First name must be between {min} and {max} characters long. 2 | lastName.size=Last name must be between {min} and {max} characters long. 3 | username.size=Username must be between {min} and {max} characters long. 4 | password.size=Password must be between {min} and {max} characters long. 5 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/webapp/WEB-INF/.DS_Store -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/views/home.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Welcome to Spitter

14 | 15 | Spittles | 16 | Register 17 | 18 |
19 | 20 | View: unknown 21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/views/page.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
7 | 8 | 9 |
10 | 11 |
Content goes here
12 | 13 |
Copyright © Craig Walls
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/views/profile.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Your Profile

14 | username
15 | First Last
16 | email 17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/WEB-INF/views/spittle.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
Spittle message
15 |
16 | spittle timestamp 17 |
18 |
19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_avatar.png -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_background.gif -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/thymeleaf/src/main/webapp/resources/images/spitter_me.jpg -------------------------------------------------------------------------------- /Chapter_06/thymeleaf/src/test/java/spitter/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spitter.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | import spittr.web.HomeController; 10 | 11 | public class HomeControllerTest { 12 | 13 | @Test 14 | public void testHomePage() throws Exception { 15 | HomeController controller = new HomeController(); 16 | MockMvc mockMvc = standaloneSetup(controller).build(); 17 | mockMvc.perform(get("/")) 18 | .andExpect(view().name("home")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_06/tiles/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_06/tiles/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_06/tiles/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 02 17:42:15 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_06/tiles/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr-Tiles' 2 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/layout/footer.jsp: -------------------------------------------------------------------------------- 1 | Copyright © Craig Walls -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/layout/header.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %> 2 | ">/images/spitter_logo_50.png" 4 | border="0"/> 5 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/layout/page.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %> 2 | <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %> 3 | <%@ page session="false" %> 4 | 5 | 6 | Spittr 7 | " > 10 | 11 | 12 | 15 |
16 | 17 |
18 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 |

Welcome to Spitter

4 | 5 | ">Spittles | 6 | ">Register 7 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/views/profile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 |

Your Profile

4 |
5 |
6 | 7 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/WEB-INF/views/spittle.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 |
3 |
4 |
5 | 6 |
7 |
8 | -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/resources/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/src/main/webapp/resources/.DS_Store -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/resources/images/spitter_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/src/main/webapp/resources/images/spitter_avatar.png -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/resources/images/spitter_background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/src/main/webapp/resources/images/spitter_background.gif -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/resources/images/spitter_logo_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/src/main/webapp/resources/images/spitter_logo_50.png -------------------------------------------------------------------------------- /Chapter_06/tiles/src/main/webapp/resources/images/spitter_me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_06/tiles/src/main/webapp/resources/images/spitter_me.jpg -------------------------------------------------------------------------------- /Chapter_06/tiles/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | public class HomeControllerTest { 10 | 11 | @Test 12 | public void testHomePage() throws Exception { 13 | HomeController controller = new HomeController(); 14 | MockMvc mockMvc = standaloneSetup(controller).build(); 15 | mockMvc.perform(get("/")) 16 | .andExpect(view().name("home")); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_07/Spittr/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 12 17:01:12 CDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr-Multipart' 2 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/web/AppWideExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import org.springframework.web.bind.annotation.ControllerAdvice; 4 | import org.springframework.web.bind.annotation.ExceptionHandler; 5 | 6 | @ControllerAdvice 7 | public class AppWideExceptionHandler { 8 | 9 | @ExceptionHandler(DuplicateSpittleException.class) 10 | public String handleNotFound() { 11 | return "error/duplicate"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/web/DuplicateSpittleException.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | public class DuplicateSpittleException extends RuntimeException { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/java/spittr/web/SpittleNotFoundException.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.NOT_FOUND, reason="Spittle Not Found") 7 | public class SpittleNotFoundException extends RuntimeException { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/resources/ValidationMessages.properties: -------------------------------------------------------------------------------- 1 | firstName.size=First name must be between {min} and {max} characters long. 2 | lastName.size=Last name must be between {min} and {max} characters long. 3 | username.size=Username must be between {min} and {max} characters long. 4 | password.size=Password must be between {min} and {max} characters long. 5 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/views/home.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Welcome to Spitter

14 | 15 | Spittles | 16 | Register 17 | 18 |
19 | 20 | View: unknown 21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/views/page.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
7 | 8 | 9 |
10 | 11 |
Content goes here
12 | 13 |
Copyright © Craig Walls
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/views/profile.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Your Profile

14 | username
15 | First Last
16 | email 17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/views/spittle.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
Spittle message
15 |
16 | spittle timestamp 17 |
18 |
19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/WEB-INF/views/uploadForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Welcome to Spitter

14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/resources/images/spitter_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/src/main/webapp/resources/images/spitter_avatar.png -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/resources/images/spitter_background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/src/main/webapp/resources/images/spitter_background.gif -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/resources/images/spitter_logo_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/src/main/webapp/resources/images/spitter_logo_50.png -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/main/webapp/resources/images/spitter_me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_07/Spittr/src/main/webapp/resources/images/spitter_me.jpg -------------------------------------------------------------------------------- /Chapter_07/Spittr/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | import spittr.web.HomeController; 10 | 11 | public class HomeControllerTest { 12 | 13 | @Test 14 | public void testHomePage() throws Exception { 15 | HomeController controller = new HomeController(); 16 | MockMvc mockMvc = standaloneSetup(controller).build(); 17 | mockMvc.perform(get("/")) 18 | .andExpect(view().name("home")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_08/SpringPizza/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 02 18:36:52 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @RequestMapping("/") 10 | public String redirectToFlow() { 11 | return "redirect:/pizza"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/PaymentException.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza; 2 | 3 | @SuppressWarnings("serial") 4 | public class PaymentException extends Exception { 5 | public PaymentException() {} 6 | } 7 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/CashOrCheckPayment.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | 4 | public class CashOrCheckPayment extends Payment { 5 | public CashOrCheckPayment() {} 6 | 7 | public String toString() { 8 | return "CASH or CHECK: $" + getAmount(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/CreditCardPayment.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | 4 | public class CreditCardPayment extends Payment { 5 | public CreditCardPayment() {} 6 | 7 | private String authorization; 8 | public void setAuthorization(String authorization) { 9 | this.authorization = authorization; 10 | } 11 | 12 | public String toString() { 13 | return "CREDIT: $" + getAmount() + " ; AUTH: " + authorization; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/Payment.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public abstract class Payment implements Serializable { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private float amount; 9 | public void setAmount(float amount) { 10 | this.amount = amount; 11 | } 12 | 13 | public float getAmount() { 14 | return amount; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/PaymentDetails.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class PaymentDetails implements Serializable { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private PaymentType paymentType; 9 | private String creditCardNumber; 10 | 11 | public PaymentType getPaymentType() { 12 | return paymentType; 13 | } 14 | 15 | public void setPaymentType(PaymentType paymentType) { 16 | this.paymentType = paymentType; 17 | } 18 | 19 | public String getCreditCardNumber() { 20 | return creditCardNumber; 21 | } 22 | 23 | public void setCreditCardNumber(String creditCardNumber) { 24 | this.creditCardNumber = creditCardNumber; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/PaymentType.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.apache.commons.lang3.text.WordUtils; 7 | 8 | public enum PaymentType { 9 | CASH, CHECK, CREDIT_CARD; 10 | 11 | public static List asList() { 12 | PaymentType[] all = PaymentType.values(); 13 | return Arrays.asList(all); 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return WordUtils.capitalizeFully(name().replace('_', ' ')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/PizzaSize.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public enum PizzaSize implements Serializable { 6 | SMALL, MEDIUM, LARGE, GINORMOUS; 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/domain/Topping.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.apache.commons.lang3.text.WordUtils; 8 | 9 | public enum Topping implements Serializable { 10 | PEPPERONI, 11 | SAUSAGE, 12 | HAMBURGER, 13 | MUSHROOM, 14 | CANADIAN_BACON, 15 | PINEAPPLE, 16 | GREEN_PEPPER, 17 | JALAPENO, 18 | TOMATO, 19 | ONION, 20 | EXTRA_CHEESE; 21 | 22 | public static List asList() { 23 | Topping[] all = Topping.values(); 24 | return Arrays.asList(all); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return WordUtils.capitalizeFully(name().replace('_', ' ')); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/service/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | 3 | @SuppressWarnings("serial") 4 | public class CustomerNotFoundException extends Exception { 5 | public CustomerNotFoundException() {} 6 | 7 | public CustomerNotFoundException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | import com.springinaction.pizza.domain.Customer; 3 | 4 | public interface CustomerService { 5 | Customer lookupCustomer(String phoneNumber) throws CustomerNotFoundException; 6 | } -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.springinaction.pizza.domain.Order; 6 | 7 | public class OrderServiceImpl { 8 | private static final Logger LOGGER = 9 | Logger.getLogger(OrderServiceImpl.class); 10 | 11 | public OrderServiceImpl() {} 12 | 13 | public void saveOrder(Order order) { 14 | LOGGER.debug("SAVING ORDER: " ); 15 | LOGGER.debug(" Customer: " + order.getCustomer().getName()); 16 | LOGGER.debug(" # of Pizzas: " + order.getPizzas().size()); 17 | LOGGER.debug(" Payment: " + order.getPayment()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/service/PaymentProcessor.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | 3 | import com.springinaction.pizza.PaymentException; 4 | 5 | /** 6 | * Simple payment processor implementation. 7 | * 8 | * Shown in brief on page 606, but fleshed out here with a dummy implementation 9 | * that declines payment for any amount over $20. 10 | * 11 | * @author wallsc 12 | */ 13 | public class PaymentProcessor { 14 | public PaymentProcessor() {} 15 | 16 | public void approveCreditCard(String creditCardNumber, String expMonth, 17 | String expYear, float amount) throws PaymentException { 18 | if (amount > 20.00) { 19 | throw new PaymentException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/java/com/springinaction/pizza/service/PricingEngine.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | 3 | import com.springinaction.pizza.domain.Order; 4 | 5 | public interface PricingEngine { 6 | public float calculateOrderTotal(Order order); 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 2 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 3 | log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{HH:mm:ss} %c{1} - %m%n 4 | 5 | log4j.appender.daily=org.apache.log4j.DailyRollingFileAppender 6 | log4j.appender.daily.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.daily.layout.ConversionPattern=[%5p] %d{HH:mm:ss} %c{1} - %m%n 8 | log4j.appender.daily.File=/Users/wallsc/logs 9 | log4j.appender.daily.DatePattern='.'yyyy-MM-dd 10 | 11 | log4j.rootLogger=WARN,stdout 12 | 13 | log4j.category.com.springinaction=DEBUG 14 | log4j.category.org.springframework=WARN 15 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | errors.email={0} has an invalid form. 2 | errors.required={0} is required. 3 | 4 | address.name=Name 5 | address.email=E-mail -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/resources/scripts/PricingEngineImpl.groovy: -------------------------------------------------------------------------------- 1 | import com.springinaction.pizza.Order; 2 | import com.springinaction.pizza.Pizza; 3 | import com.springinaction.pizza.PricingEngine; 4 | import java.io.Serializable; 5 | 6 | class PricingEngineImpl implements PricingEngine, Serializable { 7 | public float calculateOrderTotal(Order order) { 8 | print "IN GROOVY"; 9 | 10 | retun 99.99; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/flows/pizza-singleflow/thankYou.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | 3 | 4 | Spring Pizza 5 | 6 | 7 |

Thank you for your order!

8 | 9 | 10 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/flows/pizza-singleflow/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | 4 | 5 | Spring Pizza 6 | 7 | 8 |

Welcome to Spring Pizza!!!

9 | 10 | 11 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/flows/pizza/customer/deliveryWarning.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | 3 | Spring Pizza 4 | 5 | 6 |

Delivery Unavailable

7 | 8 |

The address is outside of our delivery area. The order 9 | may still be taken for carry-out.

10 | 11 | Accept | 12 | Cancel 13 | 14 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/flows/pizza/customer/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | 4 | 5 | Spring Pizza 6 | 7 | 8 |

Welcome to Spring Pizza!!!

9 | 10 | 11 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/flows/pizza/thankYou.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | 3 | 4 | Spring Pizza 5 | 6 | 7 |

Thank you for your order!

8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 18 | 20 | 21 | 22 | 23 | 24 | Finish 25 | 26 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/chooseSize.jsp: -------------------------------------------------------------------------------- 1 |

Choose size

2 |
3 | 4 | Small (12-inch)
5 | 6 | Medium (14-inch)
7 | 8 | Large (16-inch)
9 | 10 | Ginormous (20-inch)
11 | 12 | 14 | 15 | 17 | 19 |
20 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/chooseType.jsp: -------------------------------------------------------------------------------- 1 |

Choose Type

2 |
3 | Build your own
5 | 6 | Omnivore (Supreme)
7 | 8 | Carnivore (All Meat)
9 | 10 | Herbivore (Veggie)
11 | 12 | 14 | 15 | 17 | 19 |
20 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/deliveryWarning.jsp: -------------------------------------------------------------------------------- 1 |

No delivery available

2 | 3 |

The address is outside of our delivery area. The order 4 | may still be taken for carry-out.

5 | 6 | Continue | 7 | Cancel 8 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/hello.jsp: -------------------------------------------------------------------------------- 1 |

Hello world!

2 | End flow -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/home.jsp: -------------------------------------------------------------------------------- 1 |

Home

2 | Start hello flow 3 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/paymentType.jsp: -------------------------------------------------------------------------------- 1 |

Select Payment

2 | 3 | Credit Card | 4 | Cash 5 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/oldjsps/phoneNumberForm.jsp: -------------------------------------------------------------------------------- 1 | 6 |

Customer Lookup

7 |
8 | 9 | 10 | Phone number: 11 |
12 | 14 |
15 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/spring/dataaccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/spring/domain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_08/SpringPizza/src/main/webapp/WEB-INF/spring/root-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 12 17:01:12 CDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Spittr-Thymeleaf' 2 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/config/MethodSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 4 | 5 | @EnableGlobalMethodSecurity 6 | public class MethodSecurityConfig { 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/config/SecurityWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 | 5 | public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer { 6 | } 7 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.*; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/resources/ValidationMessages.properties: -------------------------------------------------------------------------------- 1 | firstName.size=First name must be between {min} and {max} characters long. 2 | lastName.size=Last name must be between {min} and {max} characters long. 3 | username.size=Username must be between {min} and {max} characters long. 4 | password.size=Password must be between {min} and {max} characters long. 5 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/webapp/WEB-INF/.DS_Store -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/views/page.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | Logout 10 |
11 | 12 |
Content goes here
13 | 14 |
Copyright © Craig Walls
15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/views/profile.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |

Your Profile

14 | username
15 | First Last
16 | email 17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/views/spittle.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | Spitter 5 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
Spittle message
15 |
16 | spittle timestamp 17 |
18 |
19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/WEB-INF/web.xml_not_used: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | springSecurityFilterChain 8 | org.springframework.web.filter.DelegatingFilterProxy 9 | 10 | 11 | 12 | springSecurityFilterChain 13 | /* 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_avatar.png -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_background.gif -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_09/thymeleaf/src/main/webapp/resources/images/spitter_me.jpg -------------------------------------------------------------------------------- /Chapter_09/thymeleaf/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | import spittr.web.HomeController; 10 | 11 | public class HomeControllerTest { 12 | 13 | @Test 14 | public void testHomePage() throws Exception { 15 | HomeController controller = new HomeController(); 16 | MockMvc mockMvc = standaloneSetup(controller).build(); 17 | mockMvc.perform(get("/")) 18 | .andExpect(view().name("home")); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/src/main/java/spittr/db/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spitter; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spitter} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpitterRepository { 12 | 13 | long count(); 14 | 15 | Spitter save(Spitter spitter); 16 | 17 | Spitter findOne(long id); 18 | 19 | Spitter findByUsername(String username); 20 | 21 | List findAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/src/main/java/spittr/db/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spittle} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpittleRepository { 12 | 13 | long count(); 14 | 15 | List findRecent(); 16 | 17 | List findRecent(int count); 18 | 19 | Spittle findOne(long id); 20 | 21 | Spittle save(Spittle spittle); 22 | 23 | List findBySpitterId(long spitterId); 24 | 25 | void delete(long id); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.util.Date; 4 | 5 | public class Spittle { 6 | private final Long id; 7 | private final Spitter spitter; 8 | private final String message; 9 | private final Date postedTime; 10 | 11 | public Spittle(Long id, Spitter spitter, String message, Date postedTime) { 12 | this.id = id; 13 | this.spitter = spitter; 14 | this.message = message; 15 | this.postedTime = postedTime; 16 | } 17 | 18 | public Long getId() { 19 | return this.id; 20 | } 21 | 22 | public String getMessage() { 23 | return this.message; 24 | } 25 | 26 | public Date getPostedTime() { 27 | return this.postedTime; 28 | } 29 | 30 | public Spitter getSpitter() { 31 | return this.spitter; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/src/main/resources/spittr/db/jdbc/schema.sql: -------------------------------------------------------------------------------- 1 | drop table if exists spittle; 2 | drop table if exists spitter; 3 | 4 | create table spitter ( 5 | id identity, 6 | username varchar(25) not null, 7 | password varchar(25) not null, 8 | fullName varchar(100) not null, 9 | email varchar(50) not null, 10 | updateByEmail boolean not null 11 | ); 12 | 13 | create table spittle ( 14 | id integer identity primary key, 15 | spitter integer not null, 16 | message varchar(2000) not null, 17 | postedTime datetime not null, 18 | foreign key (spitter) references spitter(id) 19 | ); 20 | -------------------------------------------------------------------------------- /Chapter_10/jdbc/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/src/main/java/spittr/db/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spitter; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spitter} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpitterRepository { 12 | 13 | long count(); 14 | 15 | Spitter save(Spitter spitter); 16 | 17 | Spitter findOne(long id); 18 | 19 | Spitter findByUsername(String username); 20 | 21 | List findAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/src/main/java/spittr/db/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spittle} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpittleRepository { 12 | 13 | long count(); 14 | 15 | List findRecent(); 16 | 17 | List findRecent(int count); 18 | 19 | Spittle findOne(long id); 20 | 21 | Spittle save(Spittle spittle); 22 | 23 | List findBySpitterId(long spitterId); 24 | 25 | void delete(long id); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/src/main/resources/spittr/db/hibernate4/schema.sql: -------------------------------------------------------------------------------- 1 | drop table if exists spittle; 2 | drop table if exists spitter; 3 | 4 | create table spitter ( 5 | id identity, 6 | username varchar(25) not null, 7 | password varchar(25) not null, 8 | fullName varchar(100) not null, 9 | email varchar(50) not null, 10 | updateByEmail boolean not null 11 | ); 12 | 13 | create table spittle ( 14 | id integer identity primary key, 15 | spitter integer not null, 16 | message varchar(2000) not null, 17 | postedTime datetime not null, 18 | foreign key (spitter) references spitter(id) 19 | ); 20 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_11/hibernate4/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/src/main/java/spittr/db/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spitter; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spitter} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpitterRepository { 12 | 13 | long count(); 14 | 15 | Spitter save(Spitter spitter); 16 | 17 | Spitter findOne(long id); 18 | 19 | Spitter findByUsername(String username); 20 | 21 | List findAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/src/main/java/spittr/db/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spittle} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpittleRepository { 12 | 13 | long count(); 14 | 15 | List findRecent(); 16 | 17 | List findRecent(int count); 18 | 19 | Spittle findOne(long id); 20 | 21 | Spittle save(Spittle spittle); 22 | 23 | List findBySpitterId(long spitterId); 24 | 25 | void delete(long id); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/src/main/resources/spittr/db/jpa/schema.sql: -------------------------------------------------------------------------------- 1 | drop table if exists spittle; 2 | drop table if exists spitter; 3 | 4 | create table spitter ( 5 | id identity, 6 | username varchar(25) not null, 7 | password varchar(25) not null, 8 | fullName varchar(100) not null, 9 | email varchar(50) not null, 10 | updateByEmail boolean not null 11 | ); 12 | 13 | create table spittle ( 14 | id integer identity primary key, 15 | spitter integer not null, 16 | message varchar(2000) not null, 17 | postedTime datetime not null, 18 | foreign key (spitter) references spitter(id) 19 | ); 20 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_11/jpa-hibernate/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import spittr.domain.Spitter; 8 | 9 | /** 10 | * Repository interface with operations for {@link Spitter} persistence. 11 | * @author habuma 12 | */ 13 | public interface SpitterRepository extends JpaRepository, SpitterSweeper { 14 | 15 | Spitter findByUsername(String username); 16 | 17 | List findByUsernameOrFullNameLike(String username, String fullName); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpitterRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import javax.persistence.EntityManager; 4 | import javax.persistence.PersistenceContext; 5 | 6 | public class SpitterRepositoryImpl implements SpitterSweeper { 7 | 8 | @PersistenceContext 9 | private EntityManager em; 10 | 11 | public int eliteSweep() { 12 | String update = 13 | "UPDATE Spitter spitter " + 14 | "SET spitter.status = 'Elite' " + 15 | "WHERE spitter.status = 'Newbie' " + 16 | "AND spitter.id IN (" + 17 | "SELECT s FROM Spitter s WHERE (" + 18 | " SELECT COUNT(spittles) FROM s.spittles spittles) > 10000" + 19 | ")"; 20 | return em.createQuery(update).executeUpdate(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpitterSweeper.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | public interface SpitterSweeper { 4 | 5 | int eliteSweep(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import spittr.domain.Spittle; 8 | 9 | /** 10 | * Repository interface with operations for {@link Spittle} persistence. 11 | * @author habuma 12 | */ 13 | public interface SpittleRepository extends JpaRepository, SpittleRepositoryCustom { 14 | 15 | List findBySpitterId(long spitterId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpittleRepositoryCustom.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | public interface SpittleRepositoryCustom { 8 | 9 | List findRecent(); 10 | 11 | List findRecent(int count); 12 | 13 | } -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/java/spittr/db/SpittleRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | 8 | import spittr.domain.Spittle; 9 | 10 | public class SpittleRepositoryImpl implements SpittleRepositoryCustom { 11 | 12 | @PersistenceContext 13 | private EntityManager entityManager; 14 | 15 | public List findRecent() { 16 | return findRecent(10); 17 | } 18 | 19 | public List findRecent(int count) { 20 | return (List) entityManager.createQuery("select s from Spittle s order by s.postedTime desc") 21 | .setMaxResults(count) 22 | .getResultList(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/main/resources/spittr/db/jpa/schema.sql: -------------------------------------------------------------------------------- 1 | drop table if exists spittle; 2 | drop table if exists spitter; 3 | 4 | create table spitter ( 5 | id identity, 6 | username varchar(25) not null, 7 | password varchar(25) not null, 8 | fullName varchar(100) not null, 9 | email varchar(50) not null, 10 | updateByEmail boolean not null, 11 | status varchar(10) not null 12 | ); 13 | 14 | create table spittle ( 15 | id integer identity primary key, 16 | spitter integer not null, 17 | message varchar(2000) not null, 18 | postedTime datetime not null, 19 | foreign key (spitter) references spitter(id) 20 | ); 21 | -------------------------------------------------------------------------------- /Chapter_11/jpa-springdata/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 2 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 3 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 4 | 5 | log4j.rootLogger=WARN,stdout 6 | 7 | log4j.category.org.hibernate=WARN -------------------------------------------------------------------------------- /Chapter_12/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_12/gradle.properties -------------------------------------------------------------------------------- /Chapter_12/mongo/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | target 9 | -------------------------------------------------------------------------------- /Chapter_12/mongo/README.md: -------------------------------------------------------------------------------- 1 | spring-data-mongo-samples 2 | ========================= 3 | The project is not intended to be built into a deployable JAR file, 4 | but instead includes a test case that demonstrates Spring Data Mongo. 5 | You may run this test case with 'mvn test' or import the project into 6 | your IDE and run the test there. 7 | 8 | Note that you'll need mongod running on localhost listening on port 9 | 27017 for the test to pass. 10 | -------------------------------------------------------------------------------- /Chapter_12/mongo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | compile("org.springframework:spring-context:4.0.6.RELEASE") 10 | compile("org.springframework.data:spring-data-mongodb:1.5.2.RELEASE") 11 | compile("org.mongodb:mongo-java-driver:2.11.3") // needed so that fongo will work 12 | testCompile("junit:junit-dep:4.11") 13 | testCompile("org.springframework:spring-test:4.0.6.RELEASE") 14 | } 15 | 16 | task wrapper(type: Wrapper) { 17 | gradleVersion = '2.0' 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_12/mongo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_12/mongo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_12/mongo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Aug 04 21:19:26 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_12/mongo/src/main/java/orders/config/MongoConfig.java: -------------------------------------------------------------------------------- 1 | package orders.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.data.mongodb.config.AbstractMongoConfiguration; 5 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 6 | 7 | import com.mongodb.Mongo; 8 | import com.mongodb.MongoClient; 9 | 10 | @Configuration 11 | @EnableMongoRepositories(basePackages = "orders.db") 12 | public class MongoConfig extends AbstractMongoConfiguration { 13 | 14 | @Override 15 | protected String getDatabaseName() { 16 | return "OrdersDB"; 17 | } 18 | 19 | @Override 20 | public Mongo mongo() throws Exception { 21 | return new MongoClient(); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_12/mongo/src/main/java/orders/db/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package orders.db; 2 | 3 | import java.util.List; 4 | 5 | import orders.Order; 6 | 7 | import org.springframework.data.mongodb.repository.MongoRepository; 8 | import org.springframework.data.mongodb.repository.Query; 9 | 10 | public interface OrderRepository extends MongoRepository { 11 | 12 | List findByCustomer(String customer); 13 | 14 | List findByCustomerLike(String customer); 15 | 16 | List findByCustomerAndType(String customer, String type); 17 | 18 | List getByType(String type); 19 | 20 | @Query("{customer:'Chuck Wagon'}") 21 | List findChucksOrders(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_12/mongo/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_12/neo4j/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | target 9 | -------------------------------------------------------------------------------- /Chapter_12/neo4j/README.md: -------------------------------------------------------------------------------- 1 | spring-data-neo4j-samples 2 | ========================= 3 | The project is not intended to be built into a deployable JAR file, 4 | but instead includes a test case that demonstrates Spring Data Mongo. 5 | You may run this test case with 'mvn test' or import the project into 6 | your IDE and run the test there. 7 | -------------------------------------------------------------------------------- /Chapter_12/neo4j/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | maven { url "http://m2.neo4j.org/content/repositories/releases" } 7 | } 8 | 9 | dependencies { 10 | compile("org.springframework:spring-context:4.0.6.RELEASE") 11 | compile("org.springframework.data:spring-data-neo4j:3.1.2.RELEASE") 12 | compile("javax.validation:validation-api:1.0.0.GA") 13 | testCompile("junit:junit-dep:4.11") 14 | testCompile("org.springframework:spring-test:4.0.6.RELEASE") 15 | } 16 | 17 | task wrapper(type: Wrapper) { 18 | gradleVersion = '2.0' 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_12/neo4j/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_12/neo4j/gradle.properties -------------------------------------------------------------------------------- /Chapter_12/neo4j/src/main/java/orders/db/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package orders.db; 2 | 3 | import java.util.List; 4 | 5 | import orders.Order; 6 | 7 | import org.springframework.data.neo4j.repository.GraphRepository; 8 | 9 | public interface OrderRepository extends GraphRepository { 10 | 11 | List findByCustomer(String customer); 12 | 13 | List findByCustomerLike(String customer); 14 | 15 | List findByCustomerAndType(String customer, String type); 16 | 17 | List getByType(String type); 18 | 19 | // @Query("{customer:'Chuck Wagon'}") 20 | // List findChucksOrders(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_12/neo4j/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_12/redis/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | target 9 | -------------------------------------------------------------------------------- /Chapter_12/redis/README: -------------------------------------------------------------------------------- 1 | This project contains examples from section 12.3 of Spring in Action 4. The main class 2 | to pay attention to is src/test/java/cart/CartTest.java. This class contains several 3 | test cases that exercise RedisTemplate as discussed in section 12.3. The test method 4 | names correspond to the subsections of section 12.3. 5 | 6 | As these tests perform operations against a Redis server, you must have a Redis server 7 | running and listening for requests on localhost port 6379 (Redis' default port). 8 | -------------------------------------------------------------------------------- /Chapter_12/redis/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | compile("org.springframework:spring-context:4.0.6.RELEASE") 10 | compile("org.springframework.data:spring-data-redis:1.3.2.RELEASE") 11 | compile("com.fasterxml.jackson.core:jackson-databind:2.4.1.3") 12 | compile("redis.clients:jedis:2.5.2") 13 | testCompile("junit:junit-dep:4.11") 14 | testCompile("org.springframework:spring-test:4.0.6.RELEASE") 15 | } 16 | 17 | task wrapper(type: Wrapper) { 18 | gradleVersion = '2.0' 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_12/redis/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_12/redis/gradle.properties -------------------------------------------------------------------------------- /Chapter_12/redis/src/main/java/cart/Product.java: -------------------------------------------------------------------------------- 1 | package cart; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Product implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String sku; 10 | private String name; 11 | private float price; 12 | 13 | public String getSku() { 14 | return sku; 15 | } 16 | 17 | public void setSku(String sku) { 18 | this.sku = sku; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public float getPrice() { 30 | return price; 31 | } 32 | 33 | public void setPrice(float price) { 34 | this.price = price; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_13/caching/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/main/java/spittr/config/RootConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @Configuration 8 | @ComponentScan("spittr.db") 9 | @Import({DataConfig.class, CachingConfig.class}) 10 | public class RootConfig { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/main/java/spittr/db/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import spittr.domain.Spitter; 6 | 7 | /** 8 | * Repository interface with operations for {@link Spitter} persistence. 9 | * @author habuma 10 | */ 11 | public interface SpitterRepository { 12 | 13 | long count(); 14 | 15 | Spitter save(Spitter spitter); 16 | 17 | Spitter findOne(long id); 18 | 19 | Spitter findByUsername(String username); 20 | 21 | List findAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.util.Date; 4 | 5 | public class Spittle { 6 | private final Long id; 7 | private final Spitter spitter; 8 | private final String message; 9 | private final Date postedTime; 10 | 11 | public Spittle(Long id, Spitter spitter, String message, Date postedTime) { 12 | this.id = id; 13 | this.spitter = spitter; 14 | this.message = message; 15 | this.postedTime = postedTime; 16 | } 17 | 18 | public Long getId() { 19 | return this.id; 20 | } 21 | 22 | public String getMessage() { 23 | return this.message; 24 | } 25 | 26 | public Date getPostedTime() { 27 | return this.postedTime; 28 | } 29 | 30 | public Spitter getSpitter() { 31 | return this.spitter; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/main/resources/spittr/cache/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/main/resources/spittr/db/jdbc/schema.sql: -------------------------------------------------------------------------------- 1 | drop table if exists spittle; 2 | drop table if exists spitter; 3 | 4 | create table spitter ( 5 | id identity, 6 | username varchar(25) not null, 7 | password varchar(25) not null, 8 | fullName varchar(100) not null, 9 | email varchar(50) not null, 10 | updateByEmail boolean not null 11 | ); 12 | 13 | create table spittle ( 14 | id integer identity primary key, 15 | spitter integer not null, 16 | message varchar(2000) not null, 17 | postedTime datetime not null, 18 | foreign key (spitter) references spitter(id) 19 | ); 20 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_13/caching/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.util.Date; 4 | 5 | public class Spittle { 6 | private final Long id; 7 | private final String text; 8 | private final Date postedTime; 9 | private Spitter spitter; 10 | 11 | public Spittle(Long id, Spitter spitter, String text, Date postedTime) { 12 | this.id = id; 13 | this.spitter = spitter; 14 | this.text = text; 15 | this.postedTime = postedTime; 16 | } 17 | 18 | public Long getId() { 19 | return this.id; 20 | } 21 | 22 | public String getText() { 23 | return this.text; 24 | } 25 | 26 | public Date getPostedTime() { 27 | return this.postedTime; 28 | } 29 | 30 | public Spitter getSpitter() { 31 | return spitter; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/java/spittr/service/ExpressionSecuredSpittleService.java: -------------------------------------------------------------------------------- 1 | package spittr.service; 2 | 3 | import org.springframework.security.access.prepost.PreAuthorize; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | public class ExpressionSecuredSpittleService implements SpittleService { 8 | 9 | @Override 10 | @PreAuthorize("(hasRole('ROLE_SPITTER') and #spittle.text.length() le 140) or hasRole('ROLE_PREMIUM')") 11 | public void addSpittle(Spittle spittle) { 12 | System.out.println("Method was called successfully"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/java/spittr/service/JSR250SpittleService.java: -------------------------------------------------------------------------------- 1 | package spittr.service; 2 | 3 | import javax.annotation.security.RolesAllowed; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | public class JSR250SpittleService implements SpittleService { 8 | 9 | @Override 10 | @RolesAllowed("ROLE_SPITTER") 11 | public void addSpittle(Spittle spittle) { 12 | System.out.println("Method was called successfully"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/java/spittr/service/SecuredSpittleService.java: -------------------------------------------------------------------------------- 1 | package spittr.service; 2 | 3 | import org.springframework.security.access.annotation.Secured; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | public class SecuredSpittleService implements SpittleService { 8 | 9 | @Override 10 | @Secured({"ROLE_SPITTER", "ROLE_ADMIN"}) 11 | public void addSpittle(Spittle spittle) { 12 | System.out.println("Method was called successfully"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/java/spittr/service/SpittleService.java: -------------------------------------------------------------------------------- 1 | package spittr.service; 2 | 3 | import spittr.domain.Spittle; 4 | 5 | public interface SpittleService { 6 | 7 | public abstract void addSpittle(Spittle spittle); 8 | 9 | } -------------------------------------------------------------------------------- /Chapter_14/methodsecurity/src/main/resources/collateral/coupon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_14/methodsecurity/src/main/resources/collateral/coupon.jpg -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_16/spitter-api-content-negotiation/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 12 11:24:33 CDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'spittr-api' 2 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/java/spittr/data/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spitter; 4 | 5 | public interface SpitterRepository { 6 | 7 | Spitter save(Spitter spitter); 8 | 9 | Spitter findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | void save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/") 11 | public class HomeController { 12 | 13 | @RequestMapping(method = GET) 14 | public String home(Model model) { 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 9 | 10 | 11 |

Welcome to Spitter

12 | 13 | ">Spittles | 14 | ">Register 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/webapp/WEB-INF/views/profile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 7 | 8 | 9 |

Your Profile

10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/webapp/WEB-INF/views/spittle.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Spitter 5 | " > 8 | 9 | 10 |
11 |
12 |
13 | 14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/main/webapp/resources/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .spittleList h1 { 6 | font-size: 16pt; 7 | } 8 | 9 | .spittleList ul { 10 | list-style: none; 11 | margin-left: 0px; 12 | padding-left: 0px; 13 | } 14 | 15 | .spittleList ul li:first-child { 16 | border-top: 0px; 17 | } 18 | 19 | .spittleList ul li { 20 | border-top: 1px solid #cccccc; 21 | } 22 | 23 | .spittleTime { 24 | font-size: 8pt; 25 | } 26 | 27 | .spittleLocation { 28 | font-size: 8pt; 29 | } 30 | 31 | .spittleForm h1 { 32 | font-size: 16pt; 33 | } -------------------------------------------------------------------------------- /Chapter_16/spitter-api-content-negotiation/src/test/java/spittr/web/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; 4 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; 5 | 6 | import org.junit.Test; 7 | import org.springframework.test.web.servlet.MockMvc; 8 | 9 | public class HomeControllerTest { 10 | 11 | @Test 12 | public void testHomePage() throws Exception { 13 | HomeController controller = new HomeController(); 14 | MockMvc mockMvc = standaloneSetup(controller).build(); 15 | mockMvc.perform(get("/")) 16 | .andExpect(view().name("home")); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_16/spitter-api-message-converters/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 12 11:24:33 CDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'spittr-api' 2 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/java/spittr/api/Error.java: -------------------------------------------------------------------------------- 1 | package spittr.api; 2 | 3 | public class Error { 4 | 5 | private int code; 6 | private String message; 7 | 8 | public Error(int code, String message) { 9 | this.code = code; 10 | this.message = message; 11 | } 12 | 13 | public int getCode() { 14 | return code; 15 | } 16 | 17 | public String getMessage() { 18 | return message; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/java/spittr/config/SpitterWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | import spittr.web.WebConfig; 6 | 7 | public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { RootConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/java/spittr/data/SpittleNotFoundException.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | public class SpittleNotFoundException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | private long spittleId; 8 | 9 | public SpittleNotFoundException(long spittleId) { 10 | this.spittleId = spittleId; 11 | } 12 | 13 | public long getSpittleId() { 14 | return spittleId; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import java.util.List; 4 | 5 | import spittr.Spittle; 6 | 7 | public interface SpittleRepository { 8 | 9 | List findRecentSpittles(); 10 | 11 | List findSpittles(long max, int count); 12 | 13 | Spittle findOne(long id); 14 | 15 | Spittle save(Spittle spittle); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Spittle ( 2 | id identity, 3 | message varchar(140) not null, 4 | created_at timestamp not null, 5 | latitude double, 6 | longitude double 7 | ); 8 | 9 | create table Spitter ( 10 | id identity, 11 | username varchar(20) unique not null, 12 | password varchar(20) not null, 13 | first_name varchar(30) not null, 14 | last_name varchar(30) not null, 15 | email varchar(30) not null 16 | ); -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 9 | 10 | 11 |

Welcome to Spitter

12 | 13 | ">Spittles | 14 | ">Register 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/webapp/WEB-INF/views/profile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Spitter 6 | " > 7 | 8 | 9 |

Your Profile

10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/webapp/WEB-INF/views/spittle.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Spitter 5 | " > 8 | 9 | 10 |
11 |
12 |
13 | 14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/src/main/webapp/resources/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .spittleList h1 { 6 | font-size: 16pt; 7 | } 8 | 9 | .spittleList ul { 10 | list-style: none; 11 | margin-left: 0px; 12 | padding-left: 0px; 13 | } 14 | 15 | .spittleList ul li:first-child { 16 | border-top: 0px; 17 | } 18 | 19 | .spittleList ul li { 20 | border-top: 1px solid #cccccc; 21 | } 22 | 23 | .spittleTime { 24 | font-size: 8pt; 25 | } 26 | 27 | .spittleLocation { 28 | font-size: 8pt; 29 | } 30 | 31 | .spittleForm h1 { 32 | font-size: 16pt; 33 | } -------------------------------------------------------------------------------- /Chapter_16/spitter-api-message-converters/testdata.json: -------------------------------------------------------------------------------- 1 | { 2 | "message":"Hiya!", 3 | "time":"2014-05-16", 4 | "latitude":28.419468, 5 | "longitude":-81.581195 6 | } 7 | -------------------------------------------------------------------------------- /Chapter_17/amqp/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/main/java/spittr/alerts/AlertService.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import spittr.domain.Spittle; 4 | 5 | public interface AlertService { 6 | 7 | void sendSpittleAlert(Spittle spittle); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/main/java/spittr/alerts/AlertServiceImpl.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import spittr.domain.Spittle; 7 | 8 | public class AlertServiceImpl implements AlertService { 9 | 10 | private RabbitTemplate rabbit; 11 | 12 | @Autowired 13 | public AlertServiceImpl(RabbitTemplate rabbit) { 14 | this.rabbit = rabbit; 15 | } 16 | 17 | public void sendSpittleAlert(Spittle spittle) { 18 | rabbit.convertAndSend("spittle.alert.exchange", 19 | "spittle.alerts", 20 | spittle); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/main/java/spittr/alerts/SpittleAlertHandler.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import spittr.domain.Spittle; 4 | 5 | public class SpittleAlertHandler { 6 | 7 | public void handleSpittleAlert(Spittle spittle) { 8 | System.out.println(spittle.getMessage()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/main/java/spittr/message/ConsumerMain.java: -------------------------------------------------------------------------------- 1 | package spittr.message; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class ConsumerMain { 7 | 8 | public static void main(String[] args) { 9 | ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/amqp-consumer.xml"); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Sample: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_17/amqp/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_17/jms/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_17/jms/src/main/java/spittr/JMSMain.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; 4 | import org.springframework.jms.core.JmsOperations; 5 | 6 | public class JMSMain { 7 | 8 | public static void main(String[] args) { 9 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/messaging.xml"); 10 | JmsOperations jms = context.getBean(JmsOperations.class); 11 | for(int i=0; i< 10; i++) { 12 | jms.convertAndSend("hello.queue", "Hello"); 13 | } 14 | context.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_17/jms/src/main/java/spittr/alerts/AlertService.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import spittr.domain.Spittle; 4 | 5 | public interface AlertService { 6 | 7 | void sendSpittleAlert(Spittle spittle); 8 | 9 | Spittle retrieveSpittleAlert(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_17/jms/src/main/java/spittr/alerts/SpittleAlertHandler.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import spittr.domain.Spittle; 4 | 5 | public class SpittleAlertHandler { 6 | 7 | public void handleSpittleAlert(Spittle spittle) { 8 | System.out.println(spittle.getMessage()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_17/jms/src/main/java/spittr/alerts/SpittleJmsMain.java: -------------------------------------------------------------------------------- 1 | package spittr.alerts; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import spittr.domain.Spittle; 8 | 9 | public class SpittleJmsMain { 10 | 11 | public static void main(String[] args) { 12 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/messaging.xml"); 13 | AlertService alertService = context.getBean(AlertService.class); 14 | 15 | Spittle spittle = new Spittle(1L, null, "Hello", new Date()); 16 | alertService.sendSpittleAlert(spittle); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_17/jms/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 6 | 7 | -------------------------------------------------------------------------------- /Chapter_18/STOMP/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_18/STOMP/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_18/STOMP/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_18/STOMP/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 28 15:10:18 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_18/STOMP/src/main/java/marcopolo/MarcoController.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.stereotype.Controller; 7 | 8 | @Controller 9 | public class MarcoController { 10 | 11 | private static final Logger logger = LoggerFactory 12 | .getLogger(MarcoController.class); 13 | 14 | @MessageMapping("/marco") 15 | public Shout handleShout(Shout incoming) { 16 | logger.info("Received message: " + incoming.getMessage()); 17 | 18 | try { Thread.sleep(2000); } catch (InterruptedException e) {} 19 | 20 | Shout outgoing = new Shout(); 21 | outgoing.setMessage("Polo!"); 22 | 23 | return outgoing; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_18/STOMP/src/main/java/marcopolo/Shout.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | public class Shout { 4 | 5 | private String message; 6 | 7 | public String getMessage() { 8 | return message; 9 | } 10 | 11 | public void setMessage(String message) { 12 | this.message = message; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/README: -------------------------------------------------------------------------------- 1 | This example demonstrates how to send messages to specific users. 2 | 3 | After starting the application, point your browser at localhost:8080/stomp and signin as either chuck/password or fred/password. 4 | Type messages into the form and submit. 5 | 6 | To really demonstrate user-targeted messages, open the app in two separate browsers, one signed in as fred and one signed in as chuck. 7 | Then send messages that mention the other user (e.g., "Hello @chuck" or "Hiya @fred"). 8 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_18/STOMPUser/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 28 15:10:18 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/Notification.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | public class Notification { 4 | 5 | private String message; 6 | 7 | public Notification(String message) { 8 | this.message = message; 9 | } 10 | 11 | public String getMessage() { 12 | return message; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/SecurityWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 | 5 | public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer {} 6 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import java.util.Date; 4 | 5 | public class Spittle { 6 | 7 | private Long id; 8 | private String user; 9 | private String message; 10 | private Date timestamp; 11 | 12 | public Spittle(String user, String message, Date timestamp) { 13 | this.user = user; 14 | this.message = message; 15 | this.timestamp = timestamp; 16 | } 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public String getUser() { 23 | return user; 24 | } 25 | 26 | public String getMessage() { 27 | return message; 28 | } 29 | 30 | public Date getTimestamp() { 31 | return timestamp; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/SpittleFeedService.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | public interface SpittleFeedService { 4 | 5 | void broadcastSpittle(Spittle spittle); 6 | 7 | } -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/SpittleForm.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | public class SpittleForm { 4 | 5 | private String text; 6 | 7 | public void setText(String text) { 8 | this.text = text; 9 | } 10 | 11 | public String getText() { 12 | return text; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_18/STOMPUser/src/main/java/spittr/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | public interface SpittleRepository { 4 | 5 | Spittle save(Spittle spittle); 6 | 7 | Spittle findOne(Long id); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_18/WebSocket/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_18/WebSocket/README.md: -------------------------------------------------------------------------------- 1 | low-level-websocket 2 | =================== 3 | This is a simple example of using Spring's low-level support for websocket. 4 | This is not necessarily the right thing to do in most cases, as Spring's 5 | higher-level, Spring MVC-based approach is much cleaner and easier. 6 | Moreover, the messages sent with this example are raw text, whereas STOMP 7 | would give them a defined structure. 8 | 9 | Nevertheless, this was a worthwhile project to create to understand how 10 | Spring's low-level websocket support works. 11 | -------------------------------------------------------------------------------- /Chapter_18/WebSocket/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_18/WebSocket/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_18/WebSocket/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 28 15:10:18 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_18/WebSocket/src/main/java/marcopolo/MarcoHandler.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.socket.TextMessage; 6 | import org.springframework.web.socket.WebSocketSession; 7 | import org.springframework.web.socket.handler.AbstractWebSocketHandler; 8 | 9 | public class MarcoHandler extends AbstractWebSocketHandler { 10 | 11 | private static final Logger logger = LoggerFactory.getLogger(MarcoHandler.class); 12 | 13 | @Override 14 | protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { 15 | logger.info("Received message: " + message.getPayload()); 16 | Thread.sleep(2000); 17 | session.sendMessage(new TextMessage("Polo!")); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_18/WebSocket/src/main/java/marcopolo/Shout.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | public class Shout { 4 | 5 | private String message; 6 | 7 | public String getMessage() { 8 | return message; 9 | } 10 | 11 | public void setMessage(String message) { 12 | this.message = message; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_19/mail/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_19/mail/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.util.Date; 4 | 5 | public class Spittle { 6 | private final Long id; 7 | private final String text; 8 | private final Date postedTime; 9 | private Spitter spitter; 10 | 11 | public Spittle(Long id, Spitter spitter, String text, Date postedTime) { 12 | this.id = id; 13 | this.spitter = spitter; 14 | this.text = text; 15 | this.postedTime = postedTime; 16 | } 17 | 18 | public Long getId() { 19 | return this.id; 20 | } 21 | 22 | public String getText() { 23 | return this.text; 24 | } 25 | 26 | public Date getPostedTime() { 27 | return this.postedTime; 28 | } 29 | 30 | public Spitter getSpitter() { 31 | return spitter; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /Chapter_19/mail/src/main/java/spittr/email/SpitterMailService.java: -------------------------------------------------------------------------------- 1 | package spittr.email; 2 | 3 | import javax.mail.MessagingException; 4 | 5 | import spittr.domain.Spittle; 6 | 7 | public interface SpitterMailService { 8 | 9 | public abstract void sendSimpleSpittleEmail(String to, Spittle spittle); 10 | 11 | public abstract void sendSpittleEmailWithAttachment(String to, Spittle spittle) 12 | throws MessagingException; 13 | 14 | } -------------------------------------------------------------------------------- /Chapter_19/mail/src/main/resources/collateral/coupon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_19/mail/src/main/resources/collateral/coupon.jpg -------------------------------------------------------------------------------- /Chapter_19/mail/src/test/resources/mail.properties: -------------------------------------------------------------------------------- 1 | mailserver.host=localhost 2 | mailserver.port=3025 3 | mailserver.username=app@spitter.com 4 | mailserver.password=letmein01 -------------------------------------------------------------------------------- /Chapter_21/contacts/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_21/contacts/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | 6 | dependencies { 7 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.4.RELEASE") 8 | } 9 | } 10 | 11 | apply plugin: 'java' 12 | apply plugin: 'spring-boot' 13 | 14 | jar { 15 | baseName = 'contacts' 16 | version = '0.1.0' 17 | } 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | 23 | dependencies { 24 | compile("org.springframework.boot:spring-boot-starter-web") 25 | compile("org.springframework.boot:spring-boot-starter-jdbc") 26 | compile("org.thymeleaf:thymeleaf-spring4") 27 | compile("com.h2database:h2") 28 | } 29 | 30 | task wrapper(type: Wrapper) { 31 | gradleVersion = '2.0' 32 | } -------------------------------------------------------------------------------- /Chapter_21/contacts/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jpub/SpringInAction/422d39d34f0857af2850efebde273b9bb17d5ace/Chapter_21/contacts/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter_21/contacts/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 24 21:52:24 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /Chapter_21/contacts/src/main/java/contacts/Application.java: -------------------------------------------------------------------------------- 1 | package contacts; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @ComponentScan 8 | @EnableAutoConfiguration 9 | public class Application { 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter_21/contacts/src/main/resources/public/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #eeeeee; 3 | font-family: sans-serif; 4 | } 5 | 6 | label { 7 | display: inline-block; 8 | width: 120px; 9 | text-align: right; 10 | } -------------------------------------------------------------------------------- /Chapter_21/contacts/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table contacts ( 2 | id identity, 3 | firstName varchar(30) not null, 4 | lastName varchar(50) not null, 5 | phoneNumber varchar(13), 6 | emailAddress varchar(30) 7 | ); -------------------------------------------------------------------------------- /Chapter_21/contacts_cli/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_21/contacts_cli/Contact.groovy: -------------------------------------------------------------------------------- 1 | class Contact { 2 | long id 3 | String firstName 4 | String lastName 5 | String phoneNumber 6 | String emailAddress 7 | } -------------------------------------------------------------------------------- /Chapter_21/contacts_cli/ContactController.groovy: -------------------------------------------------------------------------------- 1 | @Grab("spring-boot-starter-actuator") 2 | @Grab("thymeleaf-spring4") 3 | 4 | @Controller 5 | @RequestMapping("/") 6 | class ContactController { 7 | 8 | @Autowired 9 | ContactRepository contactRepo 10 | 11 | @RequestMapping(method=RequestMethod.GET) 12 | String home(Map model) { 13 | List contacts = contactRepo.findAll() 14 | model.putAll([contacts: contacts]) 15 | "home" 16 | } 17 | 18 | @RequestMapping(method=RequestMethod.POST) 19 | String submit(Contact contact) { 20 | contactRepo.save(contact) 21 | "redirect:/" 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter_21/contacts_cli/schema.sql: -------------------------------------------------------------------------------- 1 | create table contacts ( 2 | id identity, 3 | firstName varchar(30) not null, 4 | lastName varchar(50) not null, 5 | phoneNumber varchar(13), 6 | emailAddress varchar(30) 7 | ); -------------------------------------------------------------------------------- /Chapter_21/contacts_cli/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #eeeeee; 3 | font-family: sans-serif; 4 | } 5 | 6 | label { 7 | display: inline-block; 8 | width: 120px; 9 | text-align: right; 10 | } -------------------------------------------------------------------------------- /Chapter_21/rest_hi/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Chapter_21/rest_hi/Hi.groovy: -------------------------------------------------------------------------------- 1 | @RestController 2 | class Hi { 3 | @RequestMapping("/") 4 | String hi() { 5 | "Hi!" 6 | } 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 스프링 인 액션 3 | 4 | ![스프링 인 액션 표지](http://image.yes24.com/momo/TopCate676/MidCate001/67509460.jpg) 5 | 6 | **출판사** 제이펍 7 | **원출판사** Manning 8 | **원서명** Spring in Action(4th edition)(ISBN: 9781617291203) 9 | **저자명** 크레이그 월즈 10 | **역자명** 테크 트랜스 그룹 T4 11 | **출판일** 2015년 12월 29일 12 | **페이지** 752쪽 13 | **ISBN** 979-11-85890-38-8 (93000) 14 | 15 | [### 도서 소개 페이지 바로 가기 ###](http://jpub.tistory.com/539) 16 | 17 | 18 | --------------------------------------------------------------------------------