• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Spring vs. Java EE QConSP 2012
 

Spring vs. Java EE QConSP 2012

on

  • 25,525 views

Uma breve disputa entre as plataformas Spring e Java EE, focando bastante em como o CDI melhorou a forma de trabalhar com Java EE.

Uma breve disputa entre as plataformas Spring e Java EE, focando bastante em como o CDI melhorou a forma de trabalhar com Java EE.

Statistics

Views

Total Views
25,525
Views on SlideShare
24,188
Embed Views
1,337

Actions

Likes
25
Downloads
0
Comments
1

20 Embeds 1,337

http://fernandofranzini.wordpress.com 1110
http://caiomalheiros.wordpress.com 161
https://si0.twimg.com 15
https://fernandofranzini.wordpress.com 12
http://www.linkedin.com 9
http://us-w1.rockmelt.com 5
http://www23.jimdo.com 4
https://twimg0-a.akamaihd.net 4
http://localhost 3
http://www.infoblogs.com.br 2
http://caiomalheiros.wordpress.com. 2
http://pinterest.com 2
http://feeds2.feedburner.com 1
http://rapeeeng.wordpress.com 1
http://blackboard.libertadores.edu.co 1
https://fsulearn.ferris.edu 1
http://oracle.sociview.com 1
http://webcache.googleusercontent.com 1
https://twitter.com 1
http://infoblogs.com.br 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Spring vs. Java EE QConSP 2012 Spring vs. Java EE QConSP 2012 Presentation Transcript

  • LIGHTWEIGHTWEB APP CHAMPIONSHIP
  • QCONSP #3Duelo de titãs SPRING vs JAVA EE
  • QCONSP #3 JUÍZES
  • QCONSP #3 THE CHALLENGER
  • JAVA EE PLATFORM • lutador experiente • mudou a tática no Java EE 5 • ganhou confiança: CDI • perdeu peso para ser ágil • quer lutar na nuvem Patrocinado por: Oracle, Red Hat, IBM and otherQCONSP #3 THE CHALLENGER
  • QCONSP #3 THE CHAMPION
  • THE SPRING FRAMEWORK • sem derrota desde 2004 • nocauteou o J2EE • luta em qualquer container • golpes fortes com POJOs • sabe explorar bem seu oponente Patrocinado por: Spring SourceQCONSP #3 THE CHAMPION
  • QCONSP #3 FIGHT CARD
  • “Spring always depended on Java EE.” Bill BurkeQCONSP #3 FIGHT CARD
  • Princípio UFC (princípio hollywood) “Don’t fight us, we fight you!”QCONSP #3 ROUND #1
  • CDIQCONSP #3 ROUND #1
  • "Spring does, truly, embody many of the best practices of 2004." Gavin KingQCONSP #3 ROUND #1
  • IoC / DIQCONSP #3 ROUND #1
  • IoC / DI Spring JavaEE@Controller @Named@Scope(“request”) @RequestScopedpublic class ContatoBean { public class ContatoBean { @Autowired //@Inject @Inject private ContatoDAO dao; private ContatoDAO dao;QCONSP #3 ROUND #1
  • PersistênciaQCONSP #3 ROUND #2
  • Persistência Spring JavaEE@Repository @Statelesspublic class ContatoDAO { public class ContatoDAO { @PersistenceContext @PersistenceContext private EntityManager manager; private EntityManager manager; persistence.xml definição datasourceQCONSP #3 ROUND #2
  • PersistênciaQCONSP #3 ROUND #2
  • Persistência@Repository Spring @Stateless JavaEEpublic class ContatoDAO { public class ContatoDAO { @Autowired @Resource private JdbcTemplate template; private DataSource ds; public void salva(Contato c){ public void salva(Contato c) { try { template.update( Connection con = ds.getConn..(); "insert ... values (?, ?)", PreparedStatement ps = c.nome(), c.idade()); con.prepareStatement(“insert ..”); } ps.setString(1, c.nome());} ps.setString(1, c.idade()); ps.execute(); ps.close(); }catch(..){} ...QCONSP #3 ROUND #2
  • PersistênciaQCONSP #3 ROUND #2
  • Persistência Spring DataQCONSP #3 ROUND #2
  • Transação e ExceçãoQCONSP #3 ROUND #3
  • Transação e Exceção Spring JavaEE@Transactional(...) @TransactionAttribute(...)@Repository @Statelesspublic class ContatoDAO { public class ContatoDAO { @PersistenceContext @PersistenceContext private EntityManager manager; private EntityManager manager;<bean id=”xxxTransactionManager” ejb-jar.xml .../>QCONSP #3 ROUND #3
  • Transação e ExceçãoQCONSP #3 ROUND #3
  • Transação e Exceção Spring JavaEE@Transaction(rollbackFor= @ApplicationException(rollback=true) DaoException.class) public class DaoExceptionpublic class ContatoController{ extends Exception{}•HandlerExceptionResolver •<error-page>•AOP Proxies •filtros ou interceptadoresQCONSP #3 ROUND #3
  • QCONSP #3 ROUND #4
  • Web-Peso leveQCONSP #3 ROUND #4
  • Web-Peso leve@Controller Spring @Named JavaEE@Transactional @RequestScopedpublic class ContatoController { public class ContatoMB { @Autowired private Contato contato; private ContatoDAO dao; private List<Contato> contatos; @RequestMapping("/adicionar") @Inject public ModelAndView adicionar(Contato c){ private ContatoDAO dao; dao.salva(c); ModelAndView mv = new ModelAndView("ok"); public void salvar(){ mv.addObject("contatos", dao.lista); dao.salva(contato); return mav; zeraForm();} }QCONSP #3 ROUND #4
  • Web-Peso pesadoQCONSP #3 ROUND #4
  • Web-Peso pesado Spring JavaEEpublic class EncodingPostProcessor public class UtilMB { implements BeanPostProcessor { public String reset() {public Object postProcessBeforeInitialzation FacesContext context = (Object bean, String name) FacesContext.getCurrentInstance(); throws BeansException Application application ={if(bean instanceof context.getApplication(); AnnotationMethodHandlerAdapter) { ViewHandler viewHandler = application.getViewHandler();HttpMessageConverter<?>[] convs = UIViewRoot viewRoot =((AnnotationMethodHandlerAdapter) viewHandler.createView(context,bean).getMessageConverters(); context.getViewRoot().getViewId()); context.setViewRoot(viewRoot);for (HttpMessageConverter<?> conv : convs) { return "success"; } if(conv instanceof } StringHttpMessageConverter) {((StringHttpMessageConverter) conv).setSupportedMediaTypes(Arrays.asList(new MediaType("text", "Charset.forName("UTF-)}QCONSP #3 ROUND #4
  • Web Action-based vs. Component-basedQCONSP #3 ROUND #4
  • Web-Service - SOAPQCONSP #3 ROUND #5
  • Web-Service - SOAP Spring JavaEE@WebService @WebServicepublic class ContatosWS extends public class ContatosWS{ SpringBeanAutowiringSupport{ @Inject @Autowired ContatoDAO dao; private ContatoDAO dao; public List<Contato> listaDeContatos(){ public List<Contato> listaDeContatos() { return dao.lista(); if(dao==null{ }processInjectionBasedOnCurrentContext(this); } } ...; }}QCONSP #3 ROUND #5
  • Web-Service - RESTQCONSP #3 ROUND #5
  • Web-Service - REST@Controller Spring @Path("/") JavaEEpublic class ContatoResource { public class ContatoResource { @Autowired @Inject private ContatoDAO dao; private ContatoDAO dao; @RequestMapping( @GET value = "/contatos/{id}", @Path("/contatos/{id}") produces={"application/json"}, @Produces({"application/json"}) method=RequestMethod.GET) public Contato load(@PathParam("id") @ResponseBody Long id){ public Contato load(@PathVariable("id") return dao.busca(id); Long id) { } return dao.busca(id); } }}QCONSP #3 ROUND #5
  • MensageriaQCONSP #3 ROUND #6
  • Mensageria JavaEE - JMS InitialContext ic = new InitialContext(); ConnectionFactory cf = (ConnectionFactory)ic.lookup("Factory"); Connection con = cf.createConnection(..); Session session = con.createSession(false,AUTO_ACKNOWLEDGE); TextMessage msg = session.createTextMessage("oi jms"); Queue queue = (Queue)ic.lookup("jms/queue/loja"); QueueSender sender = session.createSender(queue); sender.send(textMessage); con.close();QCONSP #3 ROUND #6
  • Mensageria JavaEE - JMS InitialContext ic = new InitialContext(); ConnectionFactory cf = (ConnectionFactory)ic.lookup("Factory"); Connection con = cf.createConnection(..); Session session = con.createSession(false,AUTO_ACKNOWLEDGE); TextMessage msg = session.createTextMessage("oi jms"); Queue queue = (Queue)ic.lookup("jms/queue/loja"); QueueSender sender = session.createSender(queue); sender.send(textMessage); con.close();QCONSP #3 ROUND #6
  • Mensageria Spring - JMSTemplate @Autowired JmsTemplate template; @Autowired Queue queue; public void enviaMensagem() { this.template.send(queue, new MessageCreator() { public Message createMessage(Session s) throws JMSException { return session.createTextMessage("oi jms"); } }); }QCONSP #3 ROUND #6
  • Mensageria Spring - JMSTemplate @Autowired JmsTemplate template; @Autowired Queue queue; public void enviaMensagem() { this.template.send(queue, new MessageCreator() { public Message createMessage(Session s) throws JMSException { return session.createTextMessage("oi jms"); } }); }QCONSP #3 ROUND #6
  • MensageriaQCONSP #3 ROUND #6
  • Mensageria Spring IntegrationQCONSP #3 ROUND #6
  • SegurançaQCONSP #3 ROUND #7
  • Segurança JavaEE - JAAS<security-constraint> @RolesAllowed({"cliente"}) <web-resource-collection> public void salva(Contato contato){ <url-pattern>/adiciona.jsf</url-pattern> //... </web-resource-collection> } <auth-constraint> <role-name>*</role-name> @PermitAll, @DenyAll ... </auth-constraint></security-constraint><login-config> <auth-method>FORM</auth-method>v <form-login-config> <form-login-page>/login.jsf </form-login-page> </form-login-config></login-config><security-role> <role-name>*</role-name></security-role>QCONSP #3 ROUND #7
  • Segurança JavaEE - JAAS<security-constraint> @RolesAllowed({"cliente"}) <web-resource-collection> public void salva(Contato contato){ <url-pattern>/adiciona.jsf</url-pattern> //... </web-resource-collection> } <auth-constraint> <role-name>*</role-name> @PermitAll, @DenyAll ... </auth-constraint></security-constraint><login-config> <auth-method>FORM</auth-method>v <form-login-config> <form-login-page>/login.jsf </form-login-page> </form-login-config></login-config><security-role> <role-name>*</role-name></security-role>QCONSP #3 ROUND #7
  • SegurançaQCONSP #3 ROUND #7
  • Segurança Spring Security<sec:authentication-manager> @Secured({"cliente"}) <sec:authentication-provider public void salva(Contato contato){ user-service-ref="userDAO" /> //... </sec:authentication-manager> }<sec:http auto-config="true"> <sec:intercept-url <sec:authorize access="hasRole(cliente)"> pattern="/contatos.spring" um jsp restrito access="ROLE_USER" /> </sec:authorize> <sec:form-login login-page="/login-form.spring" default-target-url="/contatos.spring" login-processing-url="/login" /> <sec:logout logout-url="/logout" logout-success-url="/login-form.spring"/></sec:http>QCONSP #3 ROUND #7
  • Infra-SpringQCONSP #3 ROUND #8
  • Infra-SpringQCONSP #3 ROUND #8
  • QCONSP #3 ROUND #8
  • Infra-JavaEEQCONSP #3 ROUND #8
  • Infra-JavaEEQCONSP #3 ROUND #8
  • Infra-CloudQCONSP #3 ROUND #8
  • Extras “We will create new projects where no good solution exists.” SpringSourceQCONSP #3 ROUND #9
  • ExtrasQCONSP #3 ROUND #9
  • ExtrasQCONSP #3 ROUND #9
  • ExtrasQCONSP #3 ROUND #9
  • Especifição vs ImplementaçãoQCONSP #3 ROUND #10
  • Especifição vs ImplementaçãoQCONSP #3 ROUND #10
  • Especifição vs ImplementaçãoQCONSP #3 ROUND #10
  • Especifição vs Implementação “Standards are for standardizing, and not innovating.” Ed Burns (Líder JSF-Spec )QCONSP #3 ROUND #10
  • Especifição vs ImplementaçãoQCONSP #3 ROUND #10
  • Especifição vs Implementação "Stick to the standard when you can, leave the standards when you need." Antonio Goncalves (JCP Expert Member)QCONSP #3 ROUND #10
  • QCONSP #3 SCORE
  • QCONSP #3 SCORE
  • QCONSP #3 SCORE
  • QCONSP #3 OBRIGADO!
  • PERGUNTAS?QCONSP #3 OBRIGADO!