Your SlideShare is downloading. ×
Mathieu parisot spring profiles
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Mathieu parisot spring profiles

716
views

Published on

A l’occasion du Spring User Group, Mathieu Parisot vous fera découvrir l’utilisation des profiles spring pour changer le comportement de vos contrôleurs SpringMVC. …

A l’occasion du Spring User Group, Mathieu Parisot vous fera découvrir l’utilisation des profiles spring pour changer le comportement de vos contrôleurs SpringMVC.
Pour cela, Mathieu s’appuiera sur un cas d’utilisation sur un projet réel.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
716
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2013-06-12 Profiles Spring 1Mathieu PARISOT@matparisot
  • 2. Kézako ?"Changer le comportement de votreapplication en fonction dun (ou plusieurs)profile(s) actif(s)"2013-06-12 Profiles Spring 2
  • 3. Lexemple typeCest lhistoire dune BDD et dun développeurqui veut faire des tests…2013-06-12 Profiles Spring 3
  • 4. Mon cas dutilisation2013-06-12 Profiles Spring 4Mon ServeurServeur sécuRequestResponseHeadersAuthentification Mock authent
  • 5. La solution retenue 1/2@Controllerpublic class MyControllerNoAuthent {…@RequestMapping(value="/url1")public String method(HttpRequest request) {return "ma page 1";}…}2013-06-12 Profiles Spring 5
  • 6. La solution retenue 2/2@Controllerpublic class MyControllerMockAuthent {private @Inject MyControllerNoAuthent controller;…@RequestMapping(value="/url1")public String method(HttpRequest request) {simulateAuthentServer(request);return controller.method(request);}…}2013-06-12 Profiles Spring 6
  • 7. Sauf que…On ne peut pas avoir plusieurscontrollers sur la même URL…2013-06-12 Profiles Spring 7
  • 8. Les profiles Spring 1/2@Controller@Profile("default")public class MyControllerNoAuthent {…@RequestMapping(value="/url1")public String method(HttpRequest request) {return "ma page 1";}…}2013-06-12 Profiles Spring 8
  • 9. La solution retenue 2/2@Controller@Profile("dev")public class MyControllerMockAuthent {private @Inject MyControllerNoAuthent controller;…@RequestMapping(value="/url1")public String method(HttpRequest request) {simulateAuthentServer(request);return controller.method(request);}…}2013-06-12 Profiles Spring 9
  • 10. Activer notre profile 1/3Dans le web.xml :<context-param><param-name>spring.profiles.active</param-name><param-value>dev</param-value></context-param>2013-06-12 Profiles Spring 10
  • 11. Activer notre profile 2/3En ligne de commande :-Dspring.profile.active=dev2013-06-12 Profiles Spring 11
  • 12. Activer notre profile 3/3Via un fichier properties :public class MyCtxInitializer implementsApplicationContextInitializer<ConfigurableApplicationContext>{public void initialize(ConfigurableApplicationContext appCtx) {appCtx.getEnvironment().getPropertySources().addLast(new ResourcePropertySource("classpath:/my.properties"));appCtx.getEnvironment().setActiveProfiles(appCtx.getProperties("myProfile"));}}2013-06-12 Profiles Spring 12
  • 13. Activer notre profile 3/3 bisNe pas oublier dans le web.xml :<context-param><param-name>contextInitializerClasses</param-name><param-value>com.me.MyCtxInitializer</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>2013-06-12 Profiles Spring 13
  • 14. La conclusion⦿Cest simple⦿Pratique⦿Très peu verbeux en annotation⦿Mais ça rajoute de la magie…2013-06-12 Profiles Spring 14
  • 15. Des questions ?2013-06-12 Profiles Spring 15