├── springboot ├── settings.gradle └── src │ └── main │ ├── resources │ ├── banner.png │ ├── mypath │ │ └── 123.png │ ├── application.yml │ └── templates │ │ └── index.html │ └── java │ └── com │ └── globebill │ └── demo │ └── boot │ ├── controller │ └── DemoController.java │ ├── config │ └── MyWebAppConfigurer.java │ └── DemoBootApplication.java ├── Spittr-jsp └── src │ ├── main │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── messages.properties │ │ │ ├── spring │ │ │ │ └── root-context.xml │ │ │ └── views │ │ │ │ ├── profile.jsp │ │ │ │ ├── spittle.jsp │ │ │ │ └── home.jsp │ │ └── resources │ │ │ └── style.css │ ├── resources │ │ ├── ValidationMessages_es.properties │ │ ├── ValidationMessages.properties │ │ └── schema.sql │ └── java │ │ └── spittr │ │ ├── data │ │ ├── SpitterRepository.java │ │ └── SpittleRepository.java │ │ ├── web │ │ ├── HomeController.java │ │ └── SpittleForm.java │ │ └── config │ │ ├── SpitterWebInitializer.java │ │ ├── DataConfig.java │ │ └── RootConfig.java │ └── test │ └── java │ └── spittr │ └── web │ └── HomeControllerTest.java ├── Spring-bean-plus ├── profiles │ └── src │ │ └── main │ │ └── resources │ │ ├── test-data.sql │ │ └── schema.sql ├── conditional │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── habuma │ │ │ └── restfun │ │ │ ├── MagicBean.java │ │ │ ├── MagicConfig.java │ │ │ └── MagicExistsCondition.java │ │ └── test │ │ └── java │ │ └── com │ │ └── habuma │ │ └── restfun │ │ └── MagicExistsTest.java ├── externals │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── com │ │ │ │ └── soundsystem │ │ │ │ └── app.properties │ │ └── java │ │ │ └── com │ │ │ └── soundsystem │ │ │ └── BlankDisc.java │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── soundsystem │ │ │ ├── EnvironmentConfigWithDefaults.java │ │ │ ├── EnvironmentConfigWithRequiredProperties.java │ │ │ └── EnvironmentConfig.java │ │ └── resources │ │ └── placeholder-config.xml ├── scopedbeans │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── myapp │ │ │ │ ├── UniqueThing.java │ │ │ │ └── Notepad.java │ │ └── resources │ │ │ └── scoped-beans.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── myapp │ │ ├── ComponentScannedConfig.java │ │ └── ExplicitConfig.java └── README.md ├── Spittr-security-basic └── src │ ├── main │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── messages.properties │ │ │ └── views │ │ │ │ ├── profile.jsp │ │ │ │ ├── spittle.jsp │ │ │ │ └── home.jsp │ │ └── resources │ │ │ └── style.css │ ├── resources │ │ ├── ValidationMessages_es.properties │ │ ├── ValidationMessages.properties │ │ └── schema.sql │ └── java │ │ └── spittr │ │ ├── data │ │ ├── SpitterRepository.java │ │ └── SpittleRepository.java │ │ ├── config │ │ ├── SecurityWebInitializer.java │ │ ├── RootConfig.java │ │ ├── MyWebInitializer.java │ │ └── DataConfig.java │ │ └── web │ │ ├── HomeController.java │ │ └── SpittleForm.java │ └── test │ └── java │ └── HomeControllerTest.java ├── jms ├── .gitignore └── src │ ├── main │ └── java │ │ └── spittr │ │ ├── alerts │ │ ├── AlertService.java │ │ ├── SpittleAlertHandler.java │ │ └── SpittleJmsMain.java │ │ ├── JMSMain.java │ │ └── domain │ │ ├── Spittle.java │ │ └── Spitter.java │ └── test │ └── resources │ └── log4j.properties ├── SpringPizza └── src │ └── main │ ├── webapp │ └── WEB-INF │ │ ├── oldjsps │ │ ├── home.jsp │ │ ├── hello.jsp │ │ ├── paymentType.jsp │ │ ├── deliveryWarning.jsp │ │ ├── phoneNumberForm.jsp │ │ ├── chooseSize.jsp │ │ ├── chooseType.jsp │ │ ├── newCustomerForm.jsp │ │ └── orderDetails.jsp │ │ ├── spring │ │ ├── dataaccess.xml │ │ ├── domain.xml │ │ ├── root-config.xml │ │ ├── mvc.xml │ │ └── services.xml │ │ ├── flows │ │ ├── pizza-singleflow │ │ │ ├── thankYou.jsp │ │ │ ├── welcome.jsp │ │ │ ├── createPizza.jsp │ │ │ └── registrationForm.jsp │ │ └── pizza │ │ │ ├── customer │ │ │ ├── deliveryWarning.jsp │ │ │ ├── welcome.jsp │ │ │ └── registrationForm.jsp │ │ │ ├── thankYou.jsp │ │ │ └── order │ │ │ └── createPizza.jsp │ │ └── web.xml │ ├── resources │ ├── messages.properties │ ├── scripts │ │ └── PricingEngineImpl.groovy │ └── log4j.properties │ └── java │ └── com │ └── springinaction │ └── pizza │ ├── PaymentException.java │ ├── domain │ ├── PizzaSize.java │ ├── CashOrCheckPayment.java │ ├── Payment.java │ ├── CreditCardPayment.java │ ├── PaymentType.java │ ├── PaymentDetails.java │ ├── Topping.java │ └── Pizza.java │ ├── service │ ├── PricingEngine.java │ ├── CustomerService.java │ ├── CustomerNotFoundException.java │ ├── OrderServiceImpl.java │ ├── PaymentProcessor.java │ └── CustomerServiceImpl.java │ └── HomeController.java ├── knight └── src │ ├── main │ ├── java │ │ └── sia │ │ │ └── knights │ │ │ ├── Quest.java │ │ │ ├── Knight.java │ │ │ ├── RescueDamselQuest.java │ │ │ ├── BraveKnight.java │ │ │ ├── DamselRescuingKnight.java │ │ │ ├── SlayDragonQuest.java │ │ │ ├── config │ │ │ ├── SoundSystemConfig.java │ │ │ └── KnightConfig.java │ │ │ ├── Minstrel.java │ │ │ └── KnightMain.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ └── knight.xml │ ├── test │ ├── resources │ │ └── log4j.properties │ └── java │ │ └── sia │ │ └── knights │ │ ├── BraveKnightTest.java │ │ ├── FakePrintStream.java │ │ ├── KnightConfig.java │ │ ├── KnightXMLInjectionTest.java │ │ └── KnightJavaConfigInjectionTest.java │ └── site │ └── site.xml ├── jpa-springdata └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ └── db │ │ │ ├── SpitterSweeper.java │ │ │ ├── SpittleRepositoryCustom.java │ │ │ ├── SpittleRepository.java │ │ │ ├── SpitterRepository.java │ │ │ ├── SpitterRepositoryImpl.java │ │ │ └── SpittleRepositoryImpl.java │ └── resources │ │ └── spittr │ │ └── db │ │ └── jpa │ │ └── schema.sql │ └── test │ └── resources │ └── log4j.properties ├── Spring-mail └── src │ ├── main │ ├── resources │ │ └── collateral │ │ │ └── coupon.jpg │ └── java │ │ └── spittr │ │ ├── email │ │ └── SpitterMailService.java │ │ └── domain │ │ ├── Spittle.java │ │ └── Spitter.java │ └── test │ └── resources │ └── mail.properties ├── STOMPUser ├── src │ └── main │ │ ├── java │ │ └── spittr │ │ │ ├── SpittleFeedService.java │ │ │ ├── SpittleRepository.java │ │ │ ├── SecurityWebInitializer.java │ │ │ ├── SpittleForm.java │ │ │ ├── Notification.java │ │ │ ├── Spittle.java │ │ │ ├── WebInitializer.java │ │ │ ├── SecurityConfig.java │ │ │ ├── NaiveMapBasedSpittleRepository.java │ │ │ ├── WebSocketStompConfig.java │ │ │ ├── SpittleFeedServiceImpl.java │ │ │ └── SpittrMessageController.java │ │ └── resources │ │ └── log4j.xml └── README ├── Spittr-thymeleaf └── src │ ├── main │ ├── webapp │ │ ├── resources │ │ │ ├── images │ │ │ │ ├── spitter_me.jpg │ │ │ │ ├── spitter_avatar.png │ │ │ │ ├── spitter_logo_50.png │ │ │ │ └── spitter_background.gif │ │ │ └── style.css │ │ └── WEB-INF │ │ │ ├── spring │ │ │ └── root-context.xml │ │ │ └── views │ │ │ ├── page.html │ │ │ ├── home.html │ │ │ ├── profile.html │ │ │ └── spittle.html │ ├── resources │ │ ├── ValidationMessages_es.properties │ │ ├── ValidationMessages.properties │ │ └── schema.sql │ └── java │ │ └── spittr │ │ ├── data │ │ ├── SpitterRepository.java │ │ └── SpittleRepository.java │ │ ├── web │ │ ├── HomeController.java │ │ └── SpittleForm.java │ │ └── config │ │ ├── SpitterWebInitializer.java │ │ ├── DataConfig.java │ │ └── RootConfig.java │ └── test │ └── java │ └── spitter │ └── web │ └── HomeControllerTest.java ├── Sprittr-security-method └── src │ └── main │ ├── resources │ └── collateral │ │ └── coupon.jpg │ └── java │ └── spittr │ ├── service │ ├── SpittleService.java │ ├── JSR250SpittleService.java │ ├── SecuredSpittleService.java │ └── ExpressionSecuredSpittleService.java │ ├── domain │ ├── Spittle.java │ └── Spitter.java │ └── config │ ├── JSR250Config.java │ ├── SecuredConfig.java │ └── ExpressionSecurityConfig.java ├── caching └── src │ ├── main │ ├── resources │ │ └── spittr │ │ │ ├── cache │ │ │ └── ehcache.xml │ │ │ └── db │ │ │ └── jdbc │ │ │ └── schema.sql │ └── java │ │ └── spittr │ │ ├── config │ │ ├── RootConfig.java │ │ └── CachingConfig.java │ │ ├── db │ │ ├── SpitterRepository.java │ │ └── SpittleRepository.java │ │ └── domain │ │ ├── Spittle.java │ │ └── Spitter.java │ ├── test │ └── resources │ │ └── log4j.properties │ └── site │ └── site.xml ├── Spring-aop └── src │ └── main │ ├── java │ └── com │ │ └── vonzhou │ │ └── springinaction │ │ └── springidolaop │ │ ├── Contestant.java │ │ ├── Instrument.java │ │ ├── Thinker.java │ │ ├── Performer.java │ │ ├── MindReader.java │ │ ├── PerformanceException.java │ │ ├── GraciousContestant.java │ │ ├── Volunteer.java │ │ ├── Guitar.java │ │ ├── Magician.java │ │ ├── Stutter.java │ │ ├── Instrumentalist.java │ │ ├── RehearsalMain.java │ │ ├── MagicianMain.java │ │ ├── Main.java │ │ ├── Audience.java │ │ └── AroundAudience.java │ └── resources │ └── sneaky-magician.xml ├── Spring-aspectj └── src │ └── main │ ├── java │ └── com │ │ └── vonzhou │ │ └── springinaction │ │ └── springidol │ │ ├── Contestant.java │ │ ├── Instrument.java │ │ ├── Performer.java │ │ ├── Guitar.java │ │ ├── PerformanceException.java │ │ ├── Thinker.java │ │ ├── GraciousContestant.java │ │ ├── MindReader.java │ │ ├── Volunteer.java │ │ ├── Instrumentalist.java │ │ ├── Stutter.java │ │ ├── ContestantIntroducer.java │ │ ├── Main.java │ │ ├── AlternateMagician.java │ │ └── Magician.java │ └── resources │ ├── sneaky-magician.xml │ └── spring-idol.xml ├── amqp └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── alerts │ │ │ ├── AlertService.java │ │ │ ├── SpittleAlertHandler.java │ │ │ └── AlertServiceImpl.java │ │ │ ├── message │ │ │ ├── ConsumerMain.java │ │ │ └── ProducerMain.java │ │ │ └── domain │ │ │ ├── Spittle.java │ │ │ └── Spitter.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ └── amqp-consumer.xml │ ├── test │ └── resources │ │ └── log4j.properties │ └── site │ └── site.xml ├── Spittr └── src │ ├── main │ ├── java │ │ └── spittr │ │ │ ├── data │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ │ │ ├── web │ │ │ ├── HomeController.java │ │ │ └── SpittleForm.java │ │ │ └── config │ │ │ ├── RootConfig.java │ │ │ ├── MyWebInitializer.java │ │ │ └── DataConfig.java │ ├── resources │ │ └── schema.sql │ └── webapp │ │ ├── WEB-INF │ │ └── views │ │ │ ├── home.jsp │ │ │ ├── profile.jsp │ │ │ ├── spittle.jsp │ │ │ └── registerForm.jsp │ │ └── resources │ │ └── style.css │ └── test │ └── java │ └── HomeControllerTest.java ├── mongo └── src │ ├── test │ └── resources │ │ └── log4j.properties │ └── main │ └── java │ └── orders │ ├── db │ └── OrderRepository.java │ ├── config │ └── MongoConfig.java │ ├── Item.java │ └── Order.java ├── neo4j └── src │ ├── test │ └── resources │ │ └── log4j.properties │ └── main │ └── java │ └── orders │ ├── db │ └── OrderRepository.java │ ├── config │ └── Neo4jConfig.java │ ├── Item.java │ └── Order.java ├── Spring-jdbc └── src │ ├── test │ └── resources │ │ └── log4j.properties │ └── main │ ├── java │ └── spittr │ │ ├── dao │ │ ├── SpitterRepository.java │ │ └── SpittleRepository.java │ │ └── entity │ │ ├── Spittle.java │ │ └── Spitter.java │ └── resources │ └── jdbc │ └── schema.sql ├── hibernate4 └── src │ ├── test │ └── resources │ │ └── log4j.properties │ ├── main │ ├── java │ │ └── spittr │ │ │ └── db │ │ │ ├── SpitterRepository.java │ │ │ └── SpittleRepository.java │ └── resources │ │ └── spittr │ │ └── db │ │ └── hibernate4 │ │ └── schema.sql │ └── site │ └── site.xml ├── jpa-hibernate └── src │ ├── test │ └── resources │ │ └── log4j.properties │ ├── main │ ├── java │ │ └── spittr │ │ │ └── db │ │ │ ├── SpitterRepository.java │ │ │ ├── SpittleRepository.java │ │ │ └── jpa │ │ │ └── JpaSpitterRepository.java │ └── resources │ │ └── spittr │ │ └── db │ │ └── jpa │ │ └── schema.sql │ └── site │ └── site.xml ├── STOMP └── src │ ├── main │ ├── java │ │ └── marcopolo │ │ │ ├── Shout.java │ │ │ ├── MarcoController.java │ │ │ ├── RandomNumberMessageSender.java │ │ │ ├── WebInitializer.java │ │ │ └── WebSocketStompConfig.java │ └── resources │ │ ├── websocket-config.xml │ │ └── log4j.xml │ └── test │ └── resources │ └── log4j.xml ├── WebSocket ├── src │ └── main │ │ ├── java │ │ └── marcopolo │ │ │ ├── Shout.java │ │ │ ├── MarcoHandler.java │ │ │ ├── WebSocketConfig.java │ │ │ └── WebInitializer.java │ │ ├── resources │ │ └── websocket-config.xml │ │ └── webapp │ │ └── WEB-INF │ │ └── views │ │ └── home.html └── README.md ├── Spittr-basic └── src │ ├── main │ ├── webapp │ │ ├── WEB-INF │ │ │ └── views │ │ │ │ └── home.jsp │ │ └── resources │ │ │ └── style.css │ └── java │ │ └── spittr │ │ ├── web │ │ └── HomeController.java │ │ └── config │ │ ├── RootConfig.java │ │ └── MyWebInitializer.java │ └── test │ └── java │ └── HomeControllerTest.java ├── redis └── src │ └── main │ └── java │ └── cart │ ├── Product.java │ └── RedisConfig.java └── .gitignore /springboot/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'demo' 2 | 3 | -------------------------------------------------------------------------------- /Spittr-jsp/src/main/webapp/WEB-INF/messages.properties: -------------------------------------------------------------------------------- 1 | spitter.welcome=Welcome to Spitter! -------------------------------------------------------------------------------- /Spring-bean-plus/profiles/src/main/resources/test-data.sql: -------------------------------------------------------------------------------- 1 | insert into Things (name) values ('A') -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/webapp/WEB-INF/messages.properties: -------------------------------------------------------------------------------- 1 | spitter.welcome=Welcome to Spitter! -------------------------------------------------------------------------------- /jms/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | .springBeans 4 | .settings 5 | .project 6 | .classpath 7 | .gradle 8 | -------------------------------------------------------------------------------- /Spring-bean-plus/profiles/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table Things ( 2 | id identity, 3 | name varchar(100) 4 | ); -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/home.jsp: -------------------------------------------------------------------------------- 1 |

Home

2 | Start hello flow 3 | -------------------------------------------------------------------------------- /knight/src/main/java/sia/knights/Quest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public interface Quest { 4 | 5 | void embark(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /springboot/src/main/resources/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/springboot/src/main/resources/banner.png -------------------------------------------------------------------------------- /knight/src/main/java/sia/knights/Knight.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | public interface Knight { 4 | 5 | void embarkOnQuest(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Spring-bean-plus/conditional/src/main/java/com/habuma/restfun/MagicBean.java: -------------------------------------------------------------------------------- 1 | package com.habuma.restfun; 2 | 3 | public class MagicBean { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /Spring-bean-plus/externals/src/main/resources/com/soundsystem/app.properties: -------------------------------------------------------------------------------- 1 | disc.title=Sgt. Peppers Lonely Hearts Club Band 2 | disc.artist=The Beatles -------------------------------------------------------------------------------- /springboot/src/main/resources/mypath/123.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/springboot/src/main/resources/mypath/123.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-mail/src/main/resources/collateral/coupon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spring-mail/src/main/resources/collateral/coupon.jpg -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/hello.jsp: -------------------------------------------------------------------------------- 1 |

Hello world!

2 | End flow -------------------------------------------------------------------------------- /Spring-mail/src/test/resources/mail.properties: -------------------------------------------------------------------------------- 1 | mailserver.host=localhost 2 | mailserver.port=3025 3 | mailserver.username=app@spitter.com 4 | mailserver.password=letmein01 -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/SpittleFeedService.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | public interface SpittleFeedService { 4 | 5 | void broadcastSpittle(Spittle spittle); 6 | 7 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /Spittr-jsp/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-jsp/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/resources/images/spitter_me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-thymeleaf/src/main/webapp/resources/images/spitter_me.jpg -------------------------------------------------------------------------------- /Sprittr-security-method/src/main/resources/collateral/coupon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Sprittr-security-method/src/main/resources/collateral/coupon.jpg -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-thymeleaf/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/resources/images/spitter_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-thymeleaf/src/main/webapp/resources/images/spitter_avatar.png -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-thymeleaf/src/main/webapp/resources/images/spitter_logo_50.png -------------------------------------------------------------------------------- /caching/src/main/resources/spittr/cache/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/resources/ValidationMessages_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-security-basic/src/main/resources/ValidationMessages_es.properties -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/resources/images/spitter_background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peijie-sh/SpringInAction4/HEAD/Spittr-thymeleaf/src/main/webapp/resources/images/spitter_background.gif -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Contestant.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public interface Contestant { 4 | void receiveAward(); 5 | } -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Instrument.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public interface Instrument { 4 | public void play(); 5 | } 6 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Contestant.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public interface Contestant { 4 | void receiveAward(); 5 | } 6 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Instrument.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public interface Instrument { 4 | public void play(); 5 | } 6 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Thinker.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public interface Thinker { 4 | void thinkOfSomething(String thoughts); 5 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Performer.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public interface Performer { 4 | void perform() throws PerformanceException; 5 | } 6 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Performer.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public interface Performer { 4 | void perform() throws PerformanceException; 5 | } 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Sprittr-security-method/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 | } -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/MindReader.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public interface MindReader { 4 | void interceptThoughts(String thoughts); 5 | 6 | String getThoughts(); 7 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Guitar.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public class Guitar implements Instrument { 4 | public void play() { 5 | System.out.println("Strum strum strum"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/PerformanceException.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public class PerformanceException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/PerformanceException.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public class PerformanceException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/paymentType.jsp: -------------------------------------------------------------------------------- 1 |

Select Payment

2 | 3 | Credit Card | 4 | Cash 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Thinker.java: -------------------------------------------------------------------------------- 1 | // 2 | package com.vonzhou.springinaction.springidol; 3 | 4 | public interface Thinker { 5 | void thinkOfSomething(String thoughts); 6 | } 7 | // 8 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /springboot/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: false 4 | # mysql-config 5 | # datasource: 6 | # url: jdbc:mysql://localhost/demodb 7 | # username: root 8 | # password: qwer 9 | # driver-class-name: com.mysql.jdbc.Driver 10 | # initialize: false 11 | 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/GraciousContestant.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | 4 | public class GraciousContestant implements Contestant { 5 | 6 | public void receiveAward() { 7 | System.out.println("Why, thank you all very much!"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/MindReader.java: -------------------------------------------------------------------------------- 1 | // 2 | package com.vonzhou.springinaction.springidol; 3 | 4 | public interface MindReader { 5 | void interceptThoughts(String thoughts); 6 | 7 | String getThoughts(); 8 | } 9 | // 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/config/SecurityWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 | 5 | /** 6 | * Author LPJ 7 | * Date 2016/12/14 8 | */ 9 | public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer { 10 | } 11 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/GraciousContestant.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | 4 | /** 5 | * gracious 高尚的 6 | */ 7 | public class GraciousContestant implements Contestant { 8 | 9 | public void receiveAward() { 10 | System.out.println("Why, thank you all very much!"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /springboot/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | test 6 | 7 | 8 | qq 9 | 10 | index page. 11 | 12 | 500 13 | 404 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/spring/dataaccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spittle; 4 | 5 | import java.util.List; 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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr-basic/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 | MyMvc 6 | "> 9 | 10 | 11 |

Welcome to Spittr

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/data/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.data; 2 | 3 | import spittr.Spittle; 4 | 5 | import java.util.List; 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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Volunteer.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public class Volunteer implements Thinker { 4 | private String thoughts; 5 | 6 | public void thinkOfSomething(String thoughts) { 7 | this.thoughts = thoughts; 8 | } 9 | 10 | public String getThoughts() { 11 | return thoughts; 12 | } 13 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | ); -------------------------------------------------------------------------------- /Spittr-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 | ); -------------------------------------------------------------------------------- /Spittr-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 | ); -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /Spittr-jsp/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | ); -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Guitar.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import static java.lang.Thread.sleep; 4 | 5 | public class Guitar implements Instrument { 6 | public void play() { 7 | try{ 8 | sleep(1000); 9 | }catch (Exception e){ 10 | e.printStackTrace(); 11 | } 12 | System.out.println("Strum strum strum"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Sprittr-security-method/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Volunteer.java: -------------------------------------------------------------------------------- 1 | // 2 | package com.vonzhou.springinaction.springidol; 3 | 4 | public class Volunteer implements Thinker { 5 | private String thoughts; 6 | 7 | public void thinkOfSomething(String thoughts) { 8 | this.thoughts = thoughts; 9 | } 10 | 11 | public String getThoughts() { 12 | return thoughts; 13 | } 14 | } 15 | // 16 | -------------------------------------------------------------------------------- /Spring-jdbc/src/main/java/spittr/dao/SpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.dao; 2 | 3 | import spittr.entity.Spitter; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Author LPJ 9 | * Date 2016/12/15 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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Magician.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public class Magician implements MindReader { 4 | private String thoughts; 5 | 6 | public void interceptThoughts(String thoughts) { 7 | System.out.println("Intercepting volunteer's thoughts"); 8 | this.thoughts = thoughts; 9 | } 10 | 11 | public String getThoughts() { 12 | return thoughts; 13 | } 14 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Sprittr-security-method/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-bean-plus/scopedbeans/src/main/resources/scoped-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/phoneNumberForm.jsp: -------------------------------------------------------------------------------- 1 | 6 |

Customer Lookup

7 |
8 | 9 | 10 | Phone number: 11 |
12 | 14 |
15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Stutter.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | 5 | public class Stutter { 6 | public Object stutter(ProceedingJoinPoint call) throws Throwable { 7 | call.proceed(); 8 | call.proceed(); 9 | call.proceed(); 10 | call.proceed(); 11 | call.proceed(); 12 | call.proceed(); 13 | call.proceed(); 14 | call.proceed(); 15 | return call.proceed(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Instrumentalist.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | public class Instrumentalist implements Performer { 4 | public void perform() throws PerformanceException { 5 | instrument.play(); 6 | } 7 | 8 | private Instrument instrument; 9 | 10 | public void setInstrument(Instrument instrument) { 11 | this.instrument = instrument; 12 | } 13 | 14 | public Instrument getInstrument() { 15 | return instrument; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Stutter.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | 5 | public class Stutter { 6 | public Object stutter(ProceedingJoinPoint call) throws Throwable { 7 | call.proceed(); 8 | call.proceed(); 9 | call.proceed(); 10 | call.proceed(); 11 | call.proceed(); 12 | call.proceed(); 13 | call.proceed(); 14 | call.proceed(); 15 | return call.proceed(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 7 | 8 | @Controller 9 | @RequestMapping({"/", "/home"}) 10 | public class HomeController { 11 | 12 | @RequestMapping(method = GET) 13 | public String home() { 14 | // 返回一个名为home的视图,home.jsp 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Instrumentalist.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | public class Instrumentalist implements Performer { 4 | public void perform() throws PerformanceException { 5 | instrument.play(); 6 | } 7 | 8 | private Instrument instrument; 9 | 10 | public void setInstrument(Instrument instrument) { 11 | this.instrument = instrument; 12 | } 13 | 14 | public Instrument getInstrument() { 15 | return instrument; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-basic/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 7 | 8 | @Controller 9 | @RequestMapping({"/", "/home"}) 10 | public class HomeController { 11 | 12 | @RequestMapping(method = GET) 13 | public String home() { 14 | // 返回一个名为home的视图,home.jsp 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/ContestantIntroducer.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.DeclareParents; 5 | 6 | @Aspect 7 | public class ContestantIntroducer { 8 | 9 | @DeclareParents( // 10 | value = "com.vonzhou.springinaction.springidol.Performer+", 11 | defaultImpl = GraciousContestant.class) 12 | public static Contestant contestant; 13 | } -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 7 | 8 | @Controller 9 | @RequestMapping({"/", "/home"}) 10 | public class HomeController { 11 | 12 | @RequestMapping(method = GET) 13 | public String home() { 14 | // 返回一个名为home的视图,home.jsp 15 | return "home"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /Spring-jdbc/src/main/java/spittr/dao/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.dao; 2 | 3 | import spittr.entity.Spittle; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Author LPJ 9 | * Date 2016/12/15 10 | */ 11 | public interface SpittleRepository { 12 | long count(); 13 | 14 | List findRecent(); 15 | 16 | List findRecent(int count); 17 | 18 | Spittle findOne(long id); 19 | 20 | Spittle save(Spittle spittle); 21 | 22 | List findBySpitterId(long spitterId); 23 | 24 | void delete(long id); 25 | } 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-basic/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 | } -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Sprittr-security-method/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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spring-jdbc/src/main/resources/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /knight/src/main/resources/META-INF/spring/knight.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-basic/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.ComponentScan.Filter; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.FilterType; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | 9 | @Configuration 10 | @ComponentScan(basePackages = {"spittr"}, 11 | excludeFilters = { 12 | @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) 13 | }) 14 | public class RootConfig { 15 | } 16 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/RehearsalMain.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | /** 7 | * 排练 8 | * Created by vonzhou on 16/3/31. 9 | */ 10 | public class RehearsalMain { 11 | public static void main(String[] args) throws Exception{ 12 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-idol-around.xml"); 13 | Performer performer = (Performer)context.getBean("eddie"); 14 | performer.perform(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/globebill/demo/boot/controller/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.globebill.demo.boot.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | 7 | /** 8 | * Author lpj 9 | * Date 2016/7/26 10 | */ 11 | @RestController 12 | public class DemoController { 13 | 14 | @RequestMapping(value = {"/", "/index"}) 15 | public String index() { 16 | System.out.println("index page coming"); 17 | return "index"; 18 | } 19 | 20 | @RequestMapping("/demo") 21 | public String indexDemo() { 22 | return "home demo page"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/MagicianMain.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | /** 7 | * P99 sneaky : 卑鄙的 8 | * Created by vonzhou on 16/3/31. 9 | */ 10 | public class MagicianMain { 11 | public static void main(String[] args) throws Exception{ 12 | ApplicationContext context = new ClassPathXmlApplicationContext("sneaky-magician.xml"); 13 | Thinker volunteer = (Thinker)context.getBean("volunteer"); 14 | volunteer.thinkOfSomething("I want to play basketball, en"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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 | -------------------------------------------------------------------------------- /Spittr-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 | } -------------------------------------------------------------------------------- /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 "MyTestDB"; 17 | } 18 | 19 | @Override 20 | public Mongo mongo() throws Exception { 21 | return new MongoClient(); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | } -------------------------------------------------------------------------------- /Spittr/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.ComponentScan.Filter; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.FilterType; 7 | import org.springframework.context.annotation.Import; 8 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 9 | 10 | @Configuration 11 | @Import(DataConfig.class) 12 | @ComponentScan(basePackages = {"spittr"}, 13 | excludeFilters = { 14 | @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) 15 | }) 16 | public class RootConfig { 17 | } 18 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Main.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | /** 7 | * Created by vonzhou on 16/7/22. 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-idol.xml"); 12 | Performer performer = (Performer)context.getBean("eddie"); 13 | try { 14 | performer.perform(); 15 | } catch (PerformanceException e) { 16 | e.printStackTrace(); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr-security-basic/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.ComponentScan.Filter; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.FilterType; 7 | import org.springframework.context.annotation.Import; 8 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 9 | 10 | @Configuration 11 | @Import(DataConfig.class) 12 | @ComponentScan(basePackages = {"spittr"}, 13 | excludeFilters = { 14 | @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) 15 | }) 16 | public class RootConfig { 17 | } 18 | -------------------------------------------------------------------------------- /Spittr-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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/spring/domain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-bean-plus/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 | -------------------------------------------------------------------------------- /Spring-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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Sprittr-security-method/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 | } -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /Spittr-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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | !default.pbxuser 2 | !default.mode1v3 3 | !default.mode2v3 4 | !default.perspectivev3 5 | DerivedData 6 | project.xcworkspace 7 | 8 | .DS_Store 9 | .idea 10 | .gradle 11 | .classpath 12 | .project 13 | .settings 14 | .metadata 15 | .factorypath 16 | .springBeans 17 | .*.md.html 18 | 19 | dependency-reduced-pom.xml 20 | interpolated*.xml 21 | settings.xml 22 | 23 | build.log 24 | npm-debug.log 25 | 26 | manifest.yml 27 | 28 | local.properties 29 | 30 | overridedb.* 31 | 32 | node_modules 33 | build 34 | /code 35 | log 36 | lib/ 37 | target 38 | _site/ 39 | activemq-data 40 | 41 | *.iml 42 | *.ipr 43 | *.iws 44 | *.pbxuser 45 | *.mode1v3 46 | *.mode2v3 47 | *.moved-aside 48 | *.perspectivev3 49 | *.xccheckout 50 | *.hmap 51 | *.ipa 52 | *.xcuserstate 53 | *.war 54 | *.ear 55 | *.sw? 56 | .#* 57 | *# 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/spring/root-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Spring-bean-plus/externals/src/test/resources/placeholder-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Spring-jdbc/src/main/java/spittr/entity/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.entity; 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 | -------------------------------------------------------------------------------- /redis/src/main/java/cart/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package cart; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | 9 | @Configuration 10 | public class RedisConfig { 11 | 12 | @Bean 13 | public RedisConnectionFactory redisCF() { 14 | return new JedisConnectionFactory(); 15 | } 16 | 17 | @Bean 18 | public RedisTemplate redisTemplate(RedisConnectionFactory cf) { 19 | RedisTemplate redis = new RedisTemplate(); 20 | redis.setConnectionFactory(cf); 21 | return redis; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Spittr/src/main/java/spittr/config/MyWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * 配置DispatcherServlet,代替web.xml方式 7 | * servlet3.0以下容器(tomcat7以下)只能用web.xml配置 8 | * Author LPJ 9 | * Date 2016/12/12 10 | */ 11 | public class MyWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 12 | protected Class[] getRootConfigClasses() { 13 | return new Class[]{RootConfig.class}; 14 | } 15 | 16 | // 指定配置类 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[]{WebConfig.class}; 19 | } 20 | 21 | // 将DispatcherServlet映射到"/" 22 | protected String[] getServletMappings() { 23 | return new String[]{"/"}; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/marcopolo/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.socket.config.annotation.EnableWebSocket; 6 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 7 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; 8 | 9 | 10 | @Configuration 11 | @EnableWebSocket 12 | public class WebSocketConfig implements WebSocketConfigurer { 13 | 14 | @Override 15 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 16 | registry.addHandler(marcoHandler(), "/marco").withSockJS(); 17 | } 18 | 19 | @Bean 20 | public MarcoHandler marcoHandler() { 21 | return new MarcoHandler(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/config/MyWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * 配置DispatcherServlet,代替web.xml方式 7 | * servlet3.0以下容器(tomcat7以下)只能用web.xml配置 8 | * Author LPJ 9 | * Date 2016/12/12 10 | */ 11 | public class MyWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 12 | protected Class[] getRootConfigClasses() { 13 | return new Class[]{RootConfig.class}; 14 | } 15 | 16 | // 指定配置类 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[]{WebConfig.class}; 19 | } 20 | 21 | // 将DispatcherServlet映射到"/" 22 | protected String[] getServletMappings() { 23 | return new String[]{"/"}; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/Audience.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | 5 | public class Audience { 6 | // 表演之前 7 | public void takeSeats() { // 8 | System.out.println("The audience is taking their seats."); 9 | } 10 | // 表演之前 11 | public void turnOffCellPhones() { // 12 | System.out.println("The audience is turning off their cellphones"); 13 | } 14 | // 表演之后 15 | public void applaud() { // 16 | System.out.println("CLAP CLAP CLAP CLAP CLAP"); 17 | } 18 | // 表演失败之后 19 | public void demandRefund() { // 20 | System.out.println("Boo! We want our money back!"); 21 | } 22 | } -------------------------------------------------------------------------------- /mongo/src/main/java/orders/Item.java: -------------------------------------------------------------------------------- 1 | package orders; 2 | 3 | public class Item { 4 | 5 | private Long id; 6 | 7 | private Order order; 8 | 9 | private String product; 10 | 11 | private double price; 12 | 13 | private int quantity; 14 | 15 | public Order getOrder() { 16 | return order; 17 | } 18 | 19 | public String getProduct() { 20 | return product; 21 | } 22 | 23 | public void setProduct(String product) { 24 | this.product = product; 25 | } 26 | 27 | public double getPrice() { 28 | return price; 29 | } 30 | 31 | public void setPrice(double price) { 32 | this.price = price; 33 | } 34 | 35 | public int getQuantity() { 36 | return quantity; 37 | } 38 | 39 | public void setQuantity(int quantity) { 40 | this.quantity = quantity; 41 | } 42 | 43 | public Long getId() { 44 | return id; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /STOMP/src/main/java/marcopolo/RandomNumberMessageSender.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.messaging.simp.SimpMessagingTemplate; 5 | import org.springframework.scheduling.annotation.Scheduled; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class RandomNumberMessageSender { 10 | 11 | private SimpMessagingTemplate messaging; 12 | 13 | @Autowired 14 | public RandomNumberMessageSender(SimpMessagingTemplate messaging) { 15 | this.messaging = messaging; 16 | } 17 | 18 | @Scheduled(fixedRate=10000) 19 | public void sendRandomNumber() { 20 | Shout random = new Shout(); 21 | random.setMessage("Random # : " + (Math.random() * 100)); 22 | messaging.convertAndSend("/topic/marco", random); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/spring/mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /neo4j/src/main/java/orders/config/Neo4jConfig.java: -------------------------------------------------------------------------------- 1 | package orders.config; 2 | 3 | import org.neo4j.graphdb.GraphDatabaseService; 4 | import org.neo4j.graphdb.factory.GraphDatabaseFactory; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.data.neo4j.config.EnableNeo4jRepositories; 8 | import org.springframework.data.neo4j.config.Neo4jConfiguration; 9 | 10 | @Configuration 11 | @EnableNeo4jRepositories(basePackages = "orders.db") 12 | public class Neo4jConfig extends Neo4jConfiguration { 13 | 14 | public Neo4jConfig() { 15 | setBasePackage("orders"); 16 | } 17 | 18 | @Bean(destroyMethod="shutdown") 19 | public GraphDatabaseService graphDatabaseService() { 20 | return new GraphDatabaseFactory() 21 | .newEmbeddedDatabase("/tmp/graphdb"); 22 | } 23 | } -------------------------------------------------------------------------------- /springboot/src/main/java/com/globebill/demo/boot/config/MyWebAppConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.globebill.demo.boot.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | /** 8 | * Author lpj 9 | * Date 2016/8/3 10 | */ 11 | @Configuration 12 | public class MyWebAppConfigurer extends WebMvcConfigurerAdapter { 13 | @Override 14 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 15 | registry.addResourceHandler("/realpath/**").addResourceLocations("file:D:/work/"); 16 | registry.addResourceHandler("/mypath/**").addResourceLocations("classpath:/mypath/"); 17 | super.addResourceHandlers(registry); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/resources/sneaky-magician.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /STOMP/src/main/java/marcopolo/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import javax.servlet.ServletRegistration.Dynamic; 4 | 5 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 6 | 7 | public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class, WebSocketStompConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | @Override 25 | protected void customizeRegistration(Dynamic registration) { 26 | registration.setAsyncSupported(true); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/marcopolo/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import javax.servlet.ServletRegistration.Dynamic; 4 | 5 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 6 | 7 | public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class, WebSocketConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | @Override 25 | protected void customizeRegistration(Dynamic registration) { 26 | registration.setAsyncSupported(true); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Spittr-basic/src/main/java/spittr/config/MyWebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import spittr.web.WebConfig; 4 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 5 | 6 | /** 7 | * 配置DispatcherServlet,代替web.xml方式 8 | * servlet3.0以下容器(tomcat7以下)只能用web.xml配置 9 | * Author LPJ 10 | * Date 2016/12/12 11 | */ 12 | public class MyWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 13 | protected Class[] getRootConfigClasses() { 14 | return new Class[]{RootConfig.class}; 15 | } 16 | 17 | // 指定配置类 18 | protected Class[] getServletConfigClasses() { 19 | return new Class[]{WebConfig.class}; 20 | } 21 | 22 | // 将DispatcherServlet映射到"/" 23 | protected String[] getServletMappings() { 24 | return new String[]{"/"}; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import javax.servlet.ServletRegistration.Dynamic; 4 | 5 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 6 | 7 | public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { SecurityConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return new Class[] { WebConfig.class, WebSocketStompConfig.class }; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | @Override 25 | protected void customizeRegistration(Dynamic registration) { 26 | registration.setAsyncSupported(true); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /SpringPizza/src/main/java/com/springinaction/pizza/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.service; 2 | 3 | import com.springinaction.pizza.domain.Customer; 4 | 5 | public class CustomerServiceImpl implements CustomerService { 6 | public CustomerServiceImpl() {} 7 | 8 | public Customer lookupCustomer(String phoneNumber) throws CustomerNotFoundException { 9 | if("9725551234".equals(phoneNumber)) { 10 | Customer customer = new Customer(); 11 | customer.setId(123); 12 | customer.setName("Craig Walls"); 13 | customer.setAddress("3700 Dunlavy Rd"); 14 | customer.setCity("Denton"); 15 | customer.setState("TX"); 16 | customer.setZipCode("76210"); 17 | customer.setPhoneNumber(phoneNumber); 18 | return customer; 19 | } else { 20 | throw new CustomerNotFoundException(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/webapp/resources/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #ff9933 url(images/spitter_background.gif) no-repeat 3 | fixed left top; 4 | color: #333333; 5 | font-family: sans-serif; 6 | font-size: 0.75em; 7 | font-size-adjust: none; 8 | font-stretch: normal; 9 | font-style: normal; 10 | font-variant: normal; 11 | font-weight: normal; 12 | line-height: 1.5; 13 | text-align: center; 14 | } 15 | 16 | .spittleList h1 { 17 | font-size: 16pt; 18 | } 19 | 20 | .spittleList ul { 21 | list-style: none; 22 | margin-left: 0px; 23 | padding-left: 0px; 24 | } 25 | 26 | .spittleList ul li:first-child { 27 | border-top: 0px; 28 | } 29 | 30 | .spittleList ul li { 31 | border-top: 1px solid #cccccc; 32 | } 33 | 34 | .spittleTime { 35 | font-size: 8pt; 36 | } 37 | 38 | .spittleLocation { 39 | font-size: 8pt; 40 | } 41 | 42 | .spittleForm h1 { 43 | font-size: 16pt; 44 | } -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Main.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | /** 7 | * Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut performance 8 | * 因为aspectjrt 1.6.4 版本太低, 换成最新的就OK了,为何? 9 | * Created by vonzhou on 16/7/22. 10 | */ 11 | public class Main { 12 | public static void main(String[] args) { 13 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-idol.xml"); 14 | Performer performer = (Performer)context.getBean("eddie"); 15 | try { 16 | performer.perform(); 17 | } catch (PerformanceException e) { 18 | e.printStackTrace(); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Spring-bean-plus/README.md: -------------------------------------------------------------------------------- 1 | Chapter 3 Examples 2 | ================== 3 | This folder contains example code for chapter 3 of Spring in Action, 4th Edition. 4 | The samples are split across multiple directories: 5 | 6 | * profiles : Examples illustrating profile configuration for section 3.1. 7 | * conditionals : Examples illustrating conditional configuration for section 3.2. 8 | * scopedbeans : Examples illustrating scoped bean configuration for section 3.4. 9 | * externals : Examples illustrating external configuration for section 3.5. 10 | 11 | Note that because the examples evolve throughout the chapter and the book's text sometimes 12 | shows multiple ways of accomplishing a goal, not all variations of the code in the book will 13 | be represented in these samples. You are invited to use this source code as a starting point 14 | and experiment using the variations presented in the text. 15 | -------------------------------------------------------------------------------- /amqp/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Spittle implements Serializable { 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Long id; 10 | private Spitter spitter; 11 | private String message; 12 | private Date postedTime; 13 | 14 | public Spittle(Long id, Spitter spitter, String message, Date postedTime) { 15 | this.id = id; 16 | this.spitter = spitter; 17 | this.message = message; 18 | this.postedTime = postedTime; 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public String getMessage() { 26 | return this.message; 27 | } 28 | 29 | public Date getPostedTime() { 30 | return this.postedTime; 31 | } 32 | 33 | public Spitter getSpitter() { 34 | return this.spitter; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/AlternateMagician.java: -------------------------------------------------------------------------------- 1 | // 2 | package com.vonzhou.springinaction.springidol; 3 | 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.aspectj.lang.annotation.Before; 6 | import org.aspectj.lang.annotation.Pointcut; 7 | 8 | @Aspect 9 | public class AlternateMagician implements MindReader { 10 | private String thoughts; 11 | 12 | @Pointcut("execution(* com.springinaction.springidol." 13 | + "Thinker.thinkOfSomething(String))") 14 | public void thinking() { 15 | } 16 | 17 | @Before("thinking() && args(thoughts)") 18 | public void interceptThoughts(String thoughts) { 19 | System.out.println("Intercepting volunteer's thoughts : " + thoughts); 20 | this.thoughts = thoughts; 21 | } 22 | 23 | public String getThoughts() { 24 | return thoughts; 25 | } 26 | } 27 | // 28 | -------------------------------------------------------------------------------- /jms/src/main/java/spittr/domain/Spittle.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Spittle implements Serializable { 7 | private static final long serialVersionUID = 1L; 8 | private final Long id; 9 | private final Spitter spitter; 10 | private final String message; 11 | private final Date postedTime; 12 | 13 | public Spittle(Long id, Spitter spitter, String message, Date postedTime) { 14 | this.id = id; 15 | this.spitter = spitter; 16 | this.message = message; 17 | this.postedTime = postedTime; 18 | } 19 | 20 | public Long getId() { 21 | return this.id; 22 | } 23 | 24 | public String getMessage() { 25 | return this.message; 26 | } 27 | 28 | public Date getPostedTime() { 29 | return this.postedTime; 30 | } 31 | 32 | public Spitter getSpitter() { 33 | return this.spitter; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Spittr/src/main/java/spittr/config/DataConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.jdbc.core.JdbcOperations; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | import javax.sql.DataSource; 11 | 12 | @Configuration 13 | public class DataConfig { 14 | 15 | @Bean 16 | public DataSource dataSource() { 17 | return new EmbeddedDatabaseBuilder() 18 | .setType(EmbeddedDatabaseType.H2) 19 | .addScript("schema.sql") 20 | .build(); 21 | } 22 | 23 | @Bean 24 | public JdbcOperations jdbcTemplate(DataSource dataSource) { 25 | return new JdbcTemplate(dataSource); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Spittr-jsp/src/main/java/spittr/config/DataConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.core.JdbcOperations; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 10 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 11 | 12 | @Configuration 13 | public class DataConfig { 14 | 15 | @Bean 16 | public DataSource dataSource() { 17 | return new EmbeddedDatabaseBuilder() 18 | .setType(EmbeddedDatabaseType.H2) 19 | .addScript("schema.sql") 20 | .build(); 21 | } 22 | 23 | @Bean 24 | public JdbcOperations jdbcTemplate(DataSource dataSource) { 25 | return new JdbcTemplate(dataSource); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/java/spittr/config/DataConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.core.JdbcOperations; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 10 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 11 | 12 | @Configuration 13 | public class DataConfig { 14 | 15 | @Bean 16 | public DataSource dataSource() { 17 | return new EmbeddedDatabaseBuilder() 18 | .setType(EmbeddedDatabaseType.H2) 19 | .addScript("schema.sql") 20 | .build(); 21 | } 22 | 23 | @Bean 24 | public JdbcOperations jdbcTemplate(DataSource dataSource) { 25 | return new JdbcTemplate(dataSource); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/config/DataConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.jdbc.core.JdbcOperations; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | import javax.sql.DataSource; 11 | 12 | @Configuration 13 | public class DataConfig { 14 | 15 | @Bean 16 | public DataSource dataSource() { 17 | return new EmbeddedDatabaseBuilder() 18 | .setType(EmbeddedDatabaseType.H2) 19 | .addScript("schema.sql") 20 | .build(); 21 | } 22 | 23 | @Bean 24 | public JdbcOperations jdbcTemplate(DataSource dataSource) { 25 | return new JdbcTemplate(dataSource); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; 8 | 9 | @Configuration 10 | @EnableWebMvcSecurity 11 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 12 | 13 | @Autowired 14 | public void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { 15 | auth 16 | .inMemoryAuthentication() 17 | .withUser("chuck").password("password").roles("USER") 18 | .and() 19 | .withUser("fred").password("password").roles("USER"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/java/com/vonzhou/springinaction/springidol/Magician.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidol; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.Before; 5 | import org.aspectj.lang.annotation.Pointcut; 6 | 7 | @Aspect 8 | public class Magician implements MindReader { 9 | private String thoughts; 10 | 11 | @Pointcut("execution(* com.vonzhou.springinaction.springidol." // 12 | + "Thinker.thinkOfSomething(String)) && args(thoughts)") 13 | public void thinking(String thoughts) { 14 | } 15 | 16 | @Before("thinking(thoughts)") // 17 | public void interceptThoughts(String thoughts) { 18 | System.out.println("Intercepting volunteer's thoughts : " + thoughts); 19 | this.thoughts = thoughts; 20 | } 21 | 22 | public String getThoughts() { 23 | return thoughts; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Spittr-jsp/src/main/java/spittr/config/RootConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.ComponentScan.Filter; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.FilterType; 9 | import org.springframework.context.annotation.Import; 10 | import org.springframework.core.type.filter.RegexPatternTypeFilter; 11 | 12 | import spittr.config.RootConfig.WebPackage; 13 | 14 | @Configuration 15 | @Import(DataConfig.class) 16 | @ComponentScan(basePackages={"spittr"}, 17 | excludeFilters={ 18 | @Filter(type=FilterType.CUSTOM, value=WebPackage.class) 19 | }) 20 | public class RootConfig { 21 | public static class WebPackage extends RegexPatternTypeFilter { 22 | public WebPackage() { 23 | super(Pattern.compile("spittr\\.web")); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/java/spittr/config/RootConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.ComponentScan.Filter; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.FilterType; 9 | import org.springframework.context.annotation.Import; 10 | import org.springframework.core.type.filter.RegexPatternTypeFilter; 11 | 12 | import spittr.config.RootConfig.WebPackage; 13 | 14 | @Configuration 15 | @Import(DataConfig.class) 16 | @ComponentScan(basePackages={"spittr"}, 17 | excludeFilters={ 18 | @Filter(type=FilterType.CUSTOM, value=WebPackage.class) 19 | }) 20 | public class RootConfig { 21 | public static class WebPackage extends RegexPatternTypeFilter { 22 | public WebPackage() { 23 | super(Pattern.compile("spittr\\.web")); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/globebill/demo/boot/DemoBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.globebill.demo.boot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | 8 | import java.util.Arrays; 9 | /** 10 | * Author lpj 11 | * Date 2016/7/26 12 | */ 13 | @SpringBootApplication 14 | @EnableWebMvc 15 | public class DemoBootApplication { 16 | 17 | public static void main(String[] args) { 18 | ApplicationContext ctx = SpringApplication.run(DemoBootApplication.class, args); 19 | 20 | System.out.println("通过SpringBoot来注入依赖:"); 21 | 22 | String[] beanNames = ctx.getBeanDefinitionNames(); 23 | Arrays.sort(beanNames); 24 | for (String beanName : beanNames) { 25 | System.out.println(beanName); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Spring-aop/src/main/java/com/vonzhou/springinaction/springidolaop/AroundAudience.java: -------------------------------------------------------------------------------- 1 | package com.vonzhou.springinaction.springidolaop; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | 5 | public class AroundAudience { 6 | public void watchPerformance(ProceedingJoinPoint joinpoint) { 7 | try { 8 | System.out.println("The audience is taking their seats."); 9 | System.out.println("The audience is turning off their cellphones"); 10 | long start = System.currentTimeMillis(); // 11 | 12 | joinpoint.proceed(); // 13 | 14 | long end = System.currentTimeMillis(); // 15 | System.out.println("CLAP CLAP CLAP CLAP CLAP"); 16 | System.out.println("The performance took " + (end - start) 17 | + " milliseconds."); 18 | } catch (Throwable t) { 19 | System.out.println("Boo! We want our money back!"); // 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/newCustomerForm.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" 2 | uri="http://www.springframework.org/tags/form" %> 3 | 4 | 9 |

New customer

10 | 11 | 13 | 14 | Phone: ${requestParameters.phoneNumber}
15 | Name:
16 | Street address: 17 |
18 | City:
19 | State:
20 | Zip:
21 | 23 | 25 |
26 | -------------------------------------------------------------------------------- /caching/src/main/java/spittr/db/SpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.cache.annotation.CacheEvict; 6 | import org.springframework.cache.annotation.CachePut; 7 | import org.springframework.cache.annotation.Cacheable; 8 | 9 | import spittr.domain.Spittle; 10 | 11 | /** 12 | * Repository interface with operations for {@link Spittle} persistence. 13 | * @author habuma 14 | */ 15 | public interface SpittleRepository { 16 | 17 | long count(); 18 | 19 | @Cacheable("spittleCache") 20 | List findRecent(); 21 | 22 | List findRecent(int count); 23 | 24 | @Cacheable("spittleCache") 25 | Spittle findOne(long id); 26 | 27 | @CachePut(value="spittleCache", key="#result.id") 28 | Spittle save(Spittle spittle); 29 | 30 | @Cacheable("spittleCache") 31 | List findBySpitterId(long spitterId); 32 | 33 | @CacheEvict(value="spittleCache",condition="") 34 | void delete(long id); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /neo4j/src/main/java/orders/Item.java: -------------------------------------------------------------------------------- 1 | package orders; 2 | 3 | import org.springframework.data.neo4j.annotation.GraphId; 4 | import org.springframework.data.neo4j.annotation.NodeEntity; 5 | 6 | @NodeEntity 7 | public class Item { 8 | 9 | @GraphId 10 | private Long id; 11 | 12 | private Order order; 13 | 14 | private String product; 15 | 16 | private double price; 17 | 18 | private int quantity; 19 | 20 | public Order getOrder() { 21 | return order; 22 | } 23 | 24 | public String getProduct() { 25 | return product; 26 | } 27 | 28 | public void setProduct(String product) { 29 | this.product = product; 30 | } 31 | 32 | public double getPrice() { 33 | return price; 34 | } 35 | 36 | public void setPrice(double price) { 37 | this.price = price; 38 | } 39 | 40 | public int getQuantity() { 41 | return quantity; 42 | } 43 | 44 | public void setQuantity(int quantity) { 45 | this.quantity = quantity; 46 | } 47 | 48 | public Long getId() { 49 | return id; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/NaiveMapBasedSpittleRepository.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import org.springframework.stereotype.Repository; 9 | 10 | @Repository 11 | public class NaiveMapBasedSpittleRepository implements SpittleRepository { 12 | 13 | private AtomicLong nextId = new AtomicLong(1L); 14 | 15 | private Map spittles = new HashMap(); 16 | 17 | @Override 18 | public Spittle save(Spittle spittle) { 19 | try { 20 | Field idField = Spittle.class.getField("id"); 21 | idField.setAccessible(true); 22 | long id = nextId.incrementAndGet(); 23 | idField.set(spittle, id); 24 | spittles.put(id, spittle); 25 | } catch (Exception e) { 26 | // don't worry about it. 27 | } 28 | 29 | return spittle; 30 | } 31 | 32 | @Override 33 | public Spittle findOne(Long id) { 34 | return spittles.get(id); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /amqp/src/main/resources/META-INF/spring/amqp-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /amqp/src/main/java/spittr/message/ProducerMain.java: -------------------------------------------------------------------------------- 1 | package spittr.message; 2 | 3 | import java.util.Date; 4 | 5 | import org.junit.Ignore; 6 | import org.springframework.amqp.core.AmqpTemplate; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.support.ClassPathXmlApplicationContext; 9 | 10 | import spittr.domain.Spittle; 11 | 12 | @Ignore 13 | public class ProducerMain { 14 | 15 | public static void main(String[] args) throws Exception { 16 | 17 | ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/amqp-producer.xml"); 18 | AmqpTemplate template = (AmqpTemplate) context.getBean("rabbitTemplate"); 19 | 20 | for (int i=0; i < 20; i++) { 21 | System.out.println("Sending message #" + i); 22 | Spittle spittle = new Spittle((long) i, null, "Hello world (" + i + ")", new Date()); 23 | template.convertAndSend(spittle); 24 | Thread.sleep(5000); 25 | } 26 | 27 | System.out.println("Done!"); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Spring-aspectj/src/main/resources/spring-idol.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /caching/src/main/java/spittr/config/CachingConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import net.sf.ehcache.CacheManager; 4 | 5 | import org.springframework.cache.annotation.EnableCaching; 6 | import org.springframework.cache.ehcache.EhCacheCacheManager; 7 | import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.core.io.ClassPathResource; 11 | 12 | @Configuration 13 | @EnableCaching 14 | public class CachingConfig { 15 | 16 | @Bean 17 | public EhCacheCacheManager cacheManager(CacheManager cm) { 18 | return new EhCacheCacheManager(cm); 19 | } 20 | 21 | @Bean 22 | public EhCacheManagerFactoryBean ehcache() { 23 | EhCacheManagerFactoryBean ehCacheFactoryBean = 24 | new EhCacheManagerFactoryBean(); 25 | ehCacheFactoryBean.setConfigLocation( 26 | new ClassPathResource("spittr/cache/ehcache.xml")); 27 | return ehCacheFactoryBean; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Spittr-jsp/src/main/java/spittr/web/SpittleForm.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | 9 | public class SpittleForm { 10 | 11 | @NotNull 12 | @Size(min=1, max=140) 13 | private String message; 14 | 15 | @Min(-180) 16 | @Max(180) 17 | private Double longitude; 18 | 19 | @Min(-90) 20 | @Max(90) 21 | private Double latitude; 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | public Double getLongitude() { 32 | return longitude; 33 | } 34 | 35 | public void setLongitude(Double longitude) { 36 | this.longitude = longitude; 37 | } 38 | 39 | public Double getLatitude() { 40 | return latitude; 41 | } 42 | 43 | public void setLatitude(Double latitude) { 44 | this.latitude = latitude; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Spittr/src/main/java/spittr/web/SpittleForm.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | 9 | public class SpittleForm { 10 | 11 | @NotNull 12 | @Size(min=1, max=140) 13 | private String message; 14 | 15 | @Min(-180) 16 | @Max(180) 17 | private Double longitude; 18 | 19 | @Min(-90) 20 | @Max(90) 21 | private Double latitude; 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | public Double getLongitude() { 32 | return longitude; 33 | } 34 | 35 | public void setLongitude(Double longitude) { 36 | this.longitude = longitude; 37 | } 38 | 39 | public Double getLatitude() { 40 | return latitude; 41 | } 42 | 43 | public void setLatitude(Double latitude) { 44 | this.latitude = latitude; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /STOMP/src/main/resources/websocket-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Spittr-thymeleaf/src/main/java/spittr/web/SpittleForm.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | 9 | public class SpittleForm { 10 | 11 | @NotNull 12 | @Size(min=1, max=140) 13 | private String message; 14 | 15 | @Min(-180) 16 | @Max(180) 17 | private Double longitude; 18 | 19 | @Min(-90) 20 | @Max(90) 21 | private Double latitude; 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | public Double getLongitude() { 32 | return longitude; 33 | } 34 | 35 | public void setLongitude(Double longitude) { 36 | this.longitude = longitude; 37 | } 38 | 39 | public Double getLatitude() { 40 | return latitude; 41 | } 42 | 43 | public void setLatitude(Double latitude) { 44 | this.latitude = latitude; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/spring/services.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 10 | 11 | 15 | 16 | 18 | 19 | 20 | 22 | 23 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/main/java/spittr/web/SpittleForm.java: -------------------------------------------------------------------------------- 1 | package spittr.web; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | 9 | public class SpittleForm { 10 | 11 | @NotNull 12 | @Size(min=1, max=140) 13 | private String message; 14 | 15 | @Min(-180) 16 | @Max(180) 17 | private Double longitude; 18 | 19 | @Min(-90) 20 | @Max(90) 21 | private Double latitude; 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | public Double getLongitude() { 32 | return longitude; 33 | } 34 | 35 | public void setLongitude(Double longitude) { 36 | this.longitude = longitude; 37 | } 38 | 39 | public Double getLatitude() { 40 | return latitude; 41 | } 42 | 43 | public void setLatitude(Double latitude) { 44 | this.latitude = latitude; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WebSocket/src/main/resources/websocket-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /amqp/src/main/java/spittr/domain/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jms/src/main/java/spittr/domain/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /caching/src/main/java/spittr/domain/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Spring-jdbc/src/main/java/spittr/entity/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.entity; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Spring-mail/src/main/java/spittr/domain/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/WebSocketStompConfig.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; 6 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 7 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 8 | 9 | @Configuration 10 | @EnableWebSocketMessageBroker 11 | public class WebSocketStompConfig extends AbstractWebSocketMessageBrokerConfigurer { 12 | 13 | @Override 14 | public void registerStompEndpoints(StompEndpointRegistry registry) { 15 | registry.addEndpoint("/spittr").withSockJS(); 16 | } 17 | 18 | @Override 19 | public void configureMessageBroker(MessageBrokerRegistry registry) { 20 | // registry.enableStompBrokerRelay("/queue", "/topic"); 21 | registry.enableSimpleBroker("/queue", "/topic"); 22 | registry.setApplicationDestinationPrefixes("/app"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /STOMP/src/main/java/marcopolo/WebSocketStompConfig.java: -------------------------------------------------------------------------------- 1 | package marcopolo; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; 6 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 7 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 8 | 9 | @Configuration 10 | @EnableWebSocketMessageBroker 11 | public class WebSocketStompConfig extends AbstractWebSocketMessageBrokerConfigurer { 12 | 13 | @Override 14 | public void registerStompEndpoints(StompEndpointRegistry registry) { 15 | registry.addEndpoint("/marcopolo").withSockJS(); 16 | } 17 | 18 | @Override 19 | public void configureMessageBroker(MessageBrokerRegistry registry) { 20 | // registry.enableStompBrokerRelay("/queue", "/topic"); 21 | registry.enableSimpleBroker("/queue", "/topic"); 22 | registry.setApplicationDestinationPrefixes("/app"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/SpittleFeedServiceImpl.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.messaging.simp.SimpMessagingTemplate; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | public class SpittleFeedServiceImpl implements SpittleFeedService { 12 | 13 | private SimpMessagingTemplate messaging; 14 | private Pattern pattern = Pattern.compile("\\@(\\S+)"); 15 | 16 | @Autowired 17 | public SpittleFeedServiceImpl(SimpMessagingTemplate messaging) { 18 | this.messaging = messaging; 19 | } 20 | 21 | public void broadcastSpittle(Spittle spittle) { 22 | messaging.convertAndSend("/topic/spittlefeed", spittle); 23 | 24 | Matcher matcher = pattern.matcher(spittle.getMessage()); 25 | if (matcher.find()) { 26 | String username = matcher.group(1); 27 | messaging.convertAndSendToUser(username, "/queue/notifications", 28 | new Notification("You just got mentioned!")); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Spring-bean-plus/conditional/src/test/java/com/habuma/restfun/MagicExistsTest.java: -------------------------------------------------------------------------------- 1 | package com.habuma.restfun; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @ContextConfiguration(classes=MagicConfig.class) 14 | public class MagicExistsTest { 15 | 16 | @Autowired 17 | private ApplicationContext context; 18 | 19 | /* 20 | * This test will fail until you set a "magic" property. 21 | * You can set this property as an environment variable, a JVM system property, by adding a @BeforeClass 22 | * method and calling System.setProperty() or one of several other options. 23 | */ 24 | @Test 25 | public void shouldNotBeNull() { 26 | assertTrue(context.containsBean("magicBean")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Sprittr-security-method/src/main/java/spittr/domain/Spitter.java: -------------------------------------------------------------------------------- 1 | package spittr.domain; 2 | 3 | public class Spitter { 4 | 5 | private Long id; 6 | private String username; 7 | private String password; 8 | private String fullName; 9 | private String email; 10 | private boolean updateByEmail; 11 | 12 | public Spitter(Long id, String username, String password, String fullName, String email, boolean updateByEmail) { 13 | this.id = id; 14 | this.username = username; 15 | this.password = password; 16 | this.fullName = fullName; 17 | this.email = email; 18 | this.updateByEmail = updateByEmail; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public String getFullName() { 34 | return fullName; 35 | } 36 | 37 | public String getEmail() { 38 | return email; 39 | } 40 | 41 | public boolean isUpdateByEmail() { 42 | return updateByEmail; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/flows/pizza/order/createPizza.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 |
3 | 4 |

Create Pizza

5 | 6 | 8 | 9 | Size:
10 |
11 |
12 |
13 |
14 |
15 | 16 | Toppings:
17 |

19 | 20 | 21 | 23 | 25 |
26 |
27 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/flows/pizza-singleflow/createPizza.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 |
3 | 4 |

Create Pizza

5 | 6 | 8 | 9 | Size:
10 |
11 |
12 |
13 |
14 |
15 | 16 | Toppings:
17 |

19 | 20 | 21 | 23 | 25 |
26 |
27 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/flows/pizza/customer/registrationForm.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 |

Customer Registration

9 | 10 | 11 | 13 | Phone number:
14 | Name:
15 | Address:
16 | City:
17 | State:
18 | Zip Code:
19 | 21 | 23 |
24 | 25 | -------------------------------------------------------------------------------- /mongo/src/main/java/orders/Order.java: -------------------------------------------------------------------------------- 1 | package orders; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.mongodb.core.mapping.Document; 8 | import org.springframework.data.mongodb.core.mapping.Field; 9 | 10 | @Document 11 | public class Order { 12 | 13 | @Id 14 | private String id; 15 | 16 | @Field("customer") 17 | private String customer; 18 | 19 | private String type; 20 | 21 | private Collection items = new LinkedHashSet(); 22 | 23 | public String getCustomer() { 24 | return customer; 25 | } 26 | 27 | public void setCustomer(String customer) { 28 | this.customer = customer; 29 | } 30 | 31 | public String getType() { 32 | return type; 33 | } 34 | 35 | public void setType(String type) { 36 | this.type = type; 37 | } 38 | 39 | public Collection getItems() { 40 | return items; 41 | } 42 | 43 | public void setItems(Collection items) { 44 | this.items = items; 45 | } 46 | 47 | public String getId() { 48 | return id; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/flows/pizza-singleflow/registrationForm.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 |

Customer Registration

9 | 10 | 11 | 13 | Phone number:
14 | Name:
15 | Address:
16 | City:
17 | State:
18 | Zip Code:
19 | 21 | 23 |
24 | 25 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | contextConfigLocation 9 | /WEB-INF/spring/root-config.xml 10 | 11 | 12 | 13 | org.springframework.web.context.ContextLoaderListener 14 | 15 | 16 | 17 | SpringPizza 18 | org.springframework.web.servlet.DispatcherServlet 19 | 20 | contextConfigLocation 21 | 22 | 23 | 1 24 | 25 | 26 | 27 | SpringPizza 28 | / 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SpringPizza/src/main/java/com/springinaction/pizza/domain/Pizza.java: -------------------------------------------------------------------------------- 1 | package com.springinaction.pizza.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | @SuppressWarnings("serial") 8 | public class Pizza implements Serializable { 9 | private PizzaSize size; 10 | private List toppings; 11 | 12 | public Pizza() { 13 | toppings = new ArrayList(); 14 | size = PizzaSize.LARGE; 15 | } 16 | 17 | public PizzaSize getSize() { 18 | return size; 19 | } 20 | 21 | public void setSize(PizzaSize size) { 22 | this.size = size; 23 | } 24 | 25 | public void setSize(String sizeString) { 26 | this.size = PizzaSize.valueOf(sizeString); 27 | } 28 | 29 | public List getToppings() { 30 | return toppings; 31 | } 32 | 33 | public void setToppings(List toppings) { 34 | this.toppings = toppings; 35 | } 36 | 37 | public void setToppings(String[] toppingStrings) { 38 | for (int i = 0; i < toppingStrings.length; i++) { 39 | toppings.add(Topping.valueOf(toppingStrings[i])); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sprittr-security-method/src/main/java/spittr/config/JSR250Config.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 8 | 9 | import spittr.service.JSR250SpittleService; 10 | import spittr.service.SpittleService; 11 | 12 | @Configuration 13 | @EnableGlobalMethodSecurity(jsr250Enabled=true) 14 | public class JSR250Config extends GlobalMethodSecurityConfiguration { 15 | 16 | @Override 17 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 18 | auth 19 | .inMemoryAuthentication() 20 | .withUser("user").password("password").roles("USER"); 21 | } 22 | 23 | @Bean 24 | public SpittleService spitterService() { 25 | return new JSR250SpittleService(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Spittr/src/test/java/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import org.springframework.test.web.servlet.MockMvc; 3 | import spittr.web.HomeController; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; 8 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; 9 | 10 | /** 11 | * Author LPJ 12 | * Date 2016/12/12 13 | */ 14 | public class HomeControllerTest { 15 | 16 | // 普通测试方法,测试方法返回值 17 | @Test 18 | public void testHomePage() throws Exception { 19 | HomeController homeController = new HomeController(); 20 | assertEquals("home", homeController.home()); 21 | } 22 | 23 | // Spring3.2新特性,测试控制器和返回的视图 24 | @Test 25 | public void testHomePage2() throws Exception { 26 | HomeController controller = new HomeController(); 27 | MockMvc mockMvc = standaloneSetup(controller).build(); 28 | mockMvc.perform(get("/")).andExpect(view().name("home")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Sprittr-security-method/src/main/java/spittr/config/SecuredConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 8 | 9 | import spittr.service.SpittleService; 10 | import spittr.service.SecuredSpittleService; 11 | 12 | @Configuration 13 | @EnableGlobalMethodSecurity(securedEnabled=true) 14 | public class SecuredConfig extends GlobalMethodSecurityConfiguration { 15 | 16 | @Override 17 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 18 | auth 19 | .inMemoryAuthentication() 20 | .withUser("user").password("password").roles("USER"); 21 | } 22 | 23 | @Bean 24 | public SpittleService spitterService() { 25 | return new SecuredSpittleService(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /neo4j/src/main/java/orders/Order.java: -------------------------------------------------------------------------------- 1 | package orders; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | import java.util.Set; 6 | 7 | import org.springframework.data.neo4j.annotation.GraphId; 8 | import org.springframework.data.neo4j.annotation.NodeEntity; 9 | import org.springframework.data.neo4j.annotation.RelatedTo; 10 | 11 | @NodeEntity 12 | public class Order { 13 | 14 | @GraphId 15 | private Long id; 16 | 17 | private String customer; 18 | 19 | private String type; 20 | 21 | @RelatedTo(type="HAS_ITEMS") 22 | private Set items = new LinkedHashSet(); 23 | 24 | public String getCustomer() { 25 | return customer; 26 | } 27 | 28 | public void setCustomer(String customer) { 29 | this.customer = customer; 30 | } 31 | 32 | public String getType() { 33 | return type; 34 | } 35 | 36 | public void setType(String type) { 37 | this.type = type; 38 | } 39 | 40 | public Collection getItems() { 41 | return items; 42 | } 43 | 44 | public void setItems(Set items) { 45 | this.items = items; 46 | } 47 | 48 | public Long getId() { 49 | return id; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Spittr-basic/src/test/java/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import org.springframework.test.web.servlet.MockMvc; 3 | import spittr.web.HomeController; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; 8 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; 9 | 10 | /** 11 | * Author LPJ 12 | * Date 2016/12/12 13 | */ 14 | public class HomeControllerTest { 15 | 16 | // 普通测试方法,测试方法返回值 17 | @Test 18 | public void testHomePage() throws Exception { 19 | HomeController homeController = new HomeController(); 20 | assertEquals("home", homeController.home()); 21 | } 22 | 23 | // Spring3.2新特性,测试控制器和返回的视图 24 | @Test 25 | public void testHomePage2() throws Exception { 26 | HomeController controller = new HomeController(); 27 | MockMvc mockMvc = standaloneSetup(controller).build(); 28 | mockMvc.perform(get("/")).andExpect(view().name("home")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /knight/src/test/java/sia/knights/KnightXMLInjectionTest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.After; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | import sia.knights.Knight; 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration 16 | public class KnightXMLInjectionTest { 17 | 18 | @Autowired 19 | Knight knight; 20 | 21 | @Autowired 22 | FakePrintStream printStream; 23 | 24 | @After 25 | public void clearPrintStream() { 26 | printStream.clear(); 27 | } 28 | 29 | @Test 30 | public void shouldInjectKnightWithSlayDragonQuest() { 31 | knight.embarkOnQuest(); 32 | assertEquals( 33 | "Fa la la, the knight is so brave!\n" + 34 | "Embarking on quest to slay the dragon!\n" + 35 | "Tee hee hee, the brave knight did embark on a quest!\n", 36 | printStream.getPrintedString()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Spittr-security-basic/src/test/java/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import org.springframework.test.web.servlet.MockMvc; 3 | import spittr.web.HomeController; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; 8 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; 9 | 10 | /** 11 | * Author LPJ 12 | * Date 2016/12/12 13 | */ 14 | public class HomeControllerTest { 15 | 16 | // 普通测试方法,测试方法返回值 17 | @Test 18 | public void testHomePage() throws Exception { 19 | HomeController homeController = new HomeController(); 20 | assertEquals("home", homeController.home()); 21 | } 22 | 23 | // Spring3.2新特性,测试控制器和返回的视图 24 | @Test 25 | public void testHomePage2() throws Exception { 26 | HomeController controller = new HomeController(); 27 | MockMvc mockMvc = standaloneSetup(controller).build(); 28 | mockMvc.perform(get("/")).andExpect(view().name("home")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /jpa-hibernate/src/main/java/spittr/db/jpa/JpaSpitterRepository.java: -------------------------------------------------------------------------------- 1 | package spittr.db.jpa; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | 8 | import org.springframework.stereotype.Repository; 9 | 10 | import spittr.db.SpitterRepository; 11 | import spittr.domain.Spitter; 12 | 13 | @Repository 14 | public class JpaSpitterRepository implements SpitterRepository { 15 | 16 | @PersistenceContext 17 | private EntityManager entityManager; 18 | 19 | public long count() { 20 | return findAll().size(); 21 | } 22 | 23 | public Spitter save(Spitter spitter) { 24 | entityManager.persist(spitter); 25 | return spitter; 26 | } 27 | 28 | public Spitter findOne(long id) { 29 | return entityManager.find(Spitter.class, id); 30 | } 31 | 32 | public Spitter findByUsername(String username) { 33 | return (Spitter) entityManager.createQuery("select s from Spitter s where s.username=?").setParameter(1, username).getSingleResult(); 34 | } 35 | 36 | public List findAll() { 37 | return (List) entityManager.createQuery("select s from Spitter s").getResultList(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Sprittr-security-method/src/main/java/spittr/config/ExpressionSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package spittr.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 8 | 9 | import spittr.service.ExpressionSecuredSpittleService; 10 | import spittr.service.SpittleService; 11 | 12 | @Configuration 13 | @EnableGlobalMethodSecurity(prePostEnabled=true) 14 | public class ExpressionSecurityConfig extends GlobalMethodSecurityConfiguration { 15 | 16 | @Override 17 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 18 | auth 19 | .inMemoryAuthentication() 20 | .withUser("user").password("password").roles("USER"); 21 | } 22 | 23 | @Bean 24 | public SpittleService spitterService() { 25 | return new ExpressionSecuredSpittleService(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /WebSocket/src/main/webapp/WEB-INF/views/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Home 4 | 5 | 6 | 7 | 8 | 9 | 10 | 36 | 37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /knight/src/test/java/sia/knights/KnightJavaConfigInjectionTest.java: -------------------------------------------------------------------------------- 1 | package sia.knights; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.After; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.support.AnnotationConfigContextLoader; 12 | 13 | import sia.knights.Knight; 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(classes=KnightConfig.class,loader=AnnotationConfigContextLoader.class) 17 | public class KnightJavaConfigInjectionTest { 18 | 19 | @Autowired 20 | Knight knight; 21 | 22 | @Autowired 23 | FakePrintStream printStream; 24 | 25 | @After 26 | public void clearPrintStream() { 27 | printStream.clear(); 28 | } 29 | 30 | @Test 31 | public void shouldInjectKnightWithSlayDragonQuest() { 32 | knight.embarkOnQuest(); 33 | assertEquals( 34 | "Embarking on quest to slay the dragon!\n", 35 | printStream.getPrintedString()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Spring-aop/src/main/resources/sneaky-magician.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 14 | 15 | 16 | 17 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /SpringPizza/src/main/webapp/WEB-INF/oldjsps/orderDetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" 2 | uri="http://java.sun.com/jstl/core_rt" %> 3 | <%@ taglib prefix="fmt" 4 | uri="http://java.sun.com/jstl/fmt_rt" %> 5 | 6 | 11 | 12 |

${order.customer.name}

13 | ${order.customer.streetAddress}
14 | ${order.customer.city}, ${order.customer.state} 15 | ${order.customer.zipCode}
16 | ${order.customer.phoneNumber}
17 |
18 | Place Order | 19 | Cancel 20 |
21 |

Order total:

23 |
24 |

Pizzas:

25 | 26 | Add Pizza 27 | 28 |
29 | 30 |
  • ${pizza.size} : 31 | 32 | ${topping}, 33 | 34 |
  • 35 |
    36 | -------------------------------------------------------------------------------- /STOMPUser/src/main/java/spittr/SpittrMessageController.java: -------------------------------------------------------------------------------- 1 | package spittr; 2 | 3 | import java.security.Principal; 4 | import java.util.Date; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.messaging.handler.annotation.MessageMapping; 8 | import org.springframework.messaging.simp.annotation.SendToUser; 9 | import org.springframework.stereotype.Controller; 10 | 11 | @Controller 12 | public class SpittrMessageController { 13 | 14 | private SpittleRepository spittleRepo; 15 | private SpittleFeedService feedService; 16 | 17 | @Autowired 18 | public SpittrMessageController(SpittleRepository spittleRepo, SpittleFeedService feedService) { 19 | this.spittleRepo = spittleRepo; 20 | this.feedService = feedService; 21 | } 22 | 23 | @MessageMapping("/spittle") 24 | @SendToUser("/queue/notifications") 25 | public Notification handleSpittle(Principal principal, SpittleForm form) { 26 | Spittle spittle = new Spittle(principal.getName(), form.getText(), new Date()); 27 | spittleRepo.save(spittle); 28 | feedService.broadcastSpittle(spittle); 29 | return new Notification("Saved Spittle for user: " + principal.getName()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /STOMP/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /STOMP/src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /STOMPUser/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | --------------------------------------------------------------------------------