Your SlideShare is downloading. ×
Java EE and Spring Side-by-Side
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

Java EE and Spring Side-by-Side

14,719
views

Published on

[Note that this talk is not available outside some very specific settings but this deck is here for you as a basic resource to form a basis for your own analysis based on my reasonably objective …

[Note that this talk is not available outside some very specific settings but this deck is here for you as a basic resource to form a basis for your own analysis based on my reasonably objective extensive professional experience using both technology sets in the real world]

Java EE 7 has been one of the most significant overhauls of the platform. Just some of the changes include retiring EJB 2 entity beans and JAX-RPC, greater alignment with CDI, WebSocket/HTML 5 support, a standard API for JSON processing, the next version of JAX-RS, an overhaul of JMS, long-awaited concurrency utilities, batch processing in Java EE and much, much more. In order to make educated choices for adoption, one should understand how the widely-used Spring Framework aligns with Java EE.

This session will compare and contrast the Spring Framework with Java EE 7. We will focus on key areas that include the component development model, dependency injection, persistence, UI, REST, messaging, security and testing. Beyond API/features, the analysis will take a holistic view in covering concerns such as ease-of-use, manageability, ecosystem and vendor-neutrality.

Published in: Technology

10 Comments
26 Likes
Statistics
Notes
  • I have nothing more to add to this discussion and I believe what I have said is already more than adequate. Thanks for your input and I hope it helps folks reading the deck. At the current time, I see no reason to change it.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @undefined 'With all due respect I think you should to calm down a bit. I can understand you are upset but you really should read what you are posting and think about how it may come across if some of what you are saying was directed at you. Surely your company has policies that cover things like avoiding frivolously making serious accusations on highly subjective matters that can result in defamation suits or statements that may seem to be personal threats/harassment?'

    Sigh. Seriously? Threatening legal action is your response to being told your deck is chock full of lies of omission? And you still haven't corrected the deck yet? There is *ABSOLUTELY* no doubt that this deck is completely inaccurate/misrepresentative of today's Spring, the same Spring that developers will look at instead of, or in addition to, Java EE, fwiw. Whether this deck is so willfully or accidentally is what I want to understand.

    Thanks for the permission to use the deck. I'll be sure to steer clear of the Oracle template. I didn't want to go ahead and use your code snippets and then be sued sideways by Oracle. Or you.

    So, your points are, if I read correctly:

    * Spring Boot is almost a year old, and you don't understand how to use it. It builds on top of Spring which is 10+ years old. And which you don't know how to use. But you've learned the Glassfish console. (Congrats) You've managed to comfort yourself with the assumption that it won't work in production when, of course, it's just Spring, and Spring's been working in production for years. Often at organizations serving billions of requests. If Spring Boot is 'too early,' then surely Java EE7 is WAAAY too early and telling your customers to use Spring Boot is the most responsible thing to do? Configuration is easy with Spring Boot. For 80% cases, it's not required to get to production, but if you want to understand your opportunities Boot provides plenty of insight as to what's going on. Read the docs, dude.
    * Meh. I guess I could've been clearer here, but I'm not sure how: Spring Boot *removes* most of the configuration. Configuration that is often written using Java configuration. If you were to redo this deck as I hope to, most slides would be lines and lines of Java EE XML on the right (you've done well in capturiung those ceasless lines of configuration and boilerplate), with the blank slide on the left for the Spring configuration. There is none for most of these examples. Of course, we don't just remove the need for configuration for almost all of these use cases well served by Java EE, but we also remove it for things like RabbitMQ, SOLR, ElasticSearch, Cassandra, JMX, MongDB, Liquibase, Flyway, Spring Integration, Batch, Data, MVC, HATEOAS, Security, and a slew of other technologies for which there is no out-of-the-box Java EE analog. No configuration. Not in XML, nor Java configuration.
    * 'Spring Boot doesn't solve anything...?' Not surprised that you'd say that. See point #2: you get the same results as Java EE plus a lot more, with far less code, far less runtime footprint, and far fewer required APIs. I don't see how you can applaud Java EE and then say that in the same stroke. It's inconsistent.

    I don't want to agree to disagree. I want you to remove this travesty of a deck, or revise it: keep the almost-a-decade-old Spring configuration and show the almost-a-decade-old Java EE equivalents, or update it to Spring Boot (and so remove most of the Spring and Java EE code and have the same results). I'm trying to help you to stop misleading people. Maybe read some docs?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • With all due respect I think you should to calm down a bit. I can understand you are upset but you really should read what you are posting and think about how it may come across if some of what you are saying was directed at you. Surely your company has policies that cover things like avoiding frivolously making serious accusations on highly subjective matters or statements that may seem to be personal threats/harassment? Even barring that risk, kindly think about how some of what you are posting comes across to most professional folks that may not be so emotionally engaged on the topic? Please try to keep it technical and leave the unnecessary personal stuff out?

    I think we should largely agree to disagree, but here are a few more details since you insist:

    * The critical difference is that you actually never configure much in Java EE or even if you do, it's usually through a well documented vendor descriptor or admin console setting that's very tangible. The problem in trying to do that with Spring is that configuration overrides will likely be unavoidable for real projects and in those cases figuring out how to deal with Boot will very likely be a pain as far as I can see. But again, maybe it's fine and Boot could actually work out in the long run in the real world. The problem is that it is just still way too early to tell, which is exactly what I say during the talk.
    * CDI has actually never been in the business of system configuration via Java. That's in fact what the beans.xml is for. Some things are actually better in XML, application/system configuration happens to be one of those things. Either way, I really don't think it actually helps with the Spring configuration burden. This is exactly what I say during the talk.
    * I honestly don't think Boot helps solve anything as to mostly vanilla Java EE applications. I think it mostly helps for Spring heavy applications and those applications need the help at the moment.

    You can absolutely use this deck however you want, I've posted the actual PPT on purpose for that very reason. Just hit 'Save' and download? If you need more, just email me? You do have to be careful about using the Oracle template though - that's for Oracle employees only.

    I think I've already said I am happy to work with you on the deck. I'd prefer to do this in person but if there is a big hurry of some sort any other medium is fine - we can start via email. Kindly keep your temper under control if I don't change my mind much though. I can assure you I will try my best to sincerely listen to what you have to say. I do hope though that the overall approach is professional, respectful and calm. Frankly otherwise it's very hard to try to actually listen. If nothing else if you have to say something that is at least somewhat sensible to me, I'll make a point to mention it when I do this talk next - that's a promise :-).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Spring Boot doesn't *hide* configuration any more than Java EE 'hides' implementation details. It's simply something that's provided. It is meant to be used in the long term, not just for starting a project. You can go all the way to production without ever knowing how things are wired up, if you want. If you do want to override anything, you can: just contribute properties or even override bean definitions). These extension points are hooks, pluggable using SPIs and dependency injection. Surely you have the same sort of thing in Java EE? Surely we're able to change parts of it? (as opposed to rip it out, ignore it, do an end-run around it, or just disable it?) If nothing else, your primitive .xml deployment descriptors are a way of letting the user override things, in the same way. You do, in that scenario, have to know about the deployment descriptor, in the same way that you need what parts of Spring to override. With Spring, everything is override-able. This is called 'convention-over-configuration.' I have to assume you have heard of it. And are ignoring it. Surely you don't look at log output to learn about deployment descriptors for Glassfish, or Resin, or WebLogic, or whatever it is you're selling these days? This idea - that parts of the framework are extensible - is why we call it a framework. To quote Bob Martin, 'a framework should be open for extension, but closed for modification.' Of course our framework happens to be open-source, so you *can* modify it, if you want. But you don't need to. Just extend it using the regular hooks.

    You're not using Spring 4-features, or in the way that people are using it, you're using it as you could've in 2004. J2EE makes perfect sense in that spirit. Spring 2.0 supports a superset of J2EE 1.4. It's a bit ironic that you don't see Java configuration as being a better way to go forward, though, since that's exactly what CDI tried (but has thusfar failed) to provide. At any rate, we've supported a Java configuration story in Spring since 2005. There's been a JC story with Spring for longer than there hasn't been.

    Spring Boot makes *everything*, including Java EE (although, Spring Boot is not limited to Java EE, since we want to reach the largest group of developers and they are definitely on Java EE), much less cumbersome to work with. It is what you should compare this to. To be fair to your customers. I would like to update this deck for you. Is that OK? It's clear that you've not actually looked at Spring Boot, or that you wish to ignore it. Perhaps I can help you see clearer, beyond the logs. Most of the guides on spring.io/guides are also written using Spring Boot. I would just like to take this deck as a baseline and strike out all the irrelevant bits and replace it with a true apples-to-apples comparison. Somehow, I sense that you, or your horrible, awful, hope-murdering company would sue me if i just took your deck and started striking things out. But do you mind if I use the equivalent code snippets? Is that open source somewhere?

    You're not trolling over legitimate technical differences with this deck, you're trolling over technical differences that are mostly 10+ years old. You win the bake-off, for 2004. I want you to understand what modern developers are doing in 2014.

    Do you want this deck to be effective in converting customers from Spring? Surely your customers aren't as ignorant as to think this stuff is up-to-date? Many WebLogic/WildFly/Websphere/(and former GlassFish) customers are also Spring users. Surely they've seen Spring in the last 10 years? Don't you think just straight up lying to them will lose you more customers than not? Compete fairly. Be the change you want, Reza. Help Oracle to be more honest. I'm here to help. I'm here to help YOU. I'm here to help Oracle. Let's update this deck, together.

    I most certainly will, anyway.

    I bet, if you stopped these disingenuous comparisons, that you would have far fewer 'usual immature trolls' pestering you, too. Double win.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • [The messages before this one has somehow been deleted by an unknown party]

    * I've in fact updated this deck just a few months ago.
    * The deck does in fact have a Java config example. I don't see it as being much better or even a preferable way of doing system configuration.
    * I do indeed mention that JSF can be used with Spring.
    * I am frankly not currently convinced that Spring Boot is helpful beyond just getting started with Spring. The problem is that it does not really eliminate Spring configuration, it merely tries to hide it. The problem with this approach is that if you need to customize as you will very likely need to do with a non-trivial Spring application (e.g. do anything beyond simple defaults) you have to go through a painful process of reverse engineering configuration from log output! For this reason, I've decided to leave out Spring Boot from the analysis beyond simply talking though it as something potentially promising to make Spring less cumbersome to work with. Perhaps this will change as Spring Boot matures a bit more and get's more traction among real Spring users, even in terms of it's documentation that I found rather skimpy at the moment. For the record I had the similar reservations with Spring Roo that I think has largely proven to be correct in terms of real adoption among Spring users.
    * The baseline I've chosen is Spring 4 and Java EE 7. In this context, J2EE makes little sense.
    * In fact beans.xml and web.xml is optional in Java EE 7, albeit a pretty minimal persistence.xml is not.
    * You can in fact register anything you want with CDI injection, JNDI or otherwise. This is the same as it is in Spring. In fact, it is possible to integrate CDI with Spring if one so wishes.

    If we have to (sadly) troll each other over legitimate technical differences, so be it - such is life I guess. I am happy to defend my honest opinion - who knows maybe it's even one way at arriving at the truth?

    However I suggest a far less unpleasant and perhaps more useful approach - let's discuss the deck in person next time we meet in a civil and mutually respectable fashion as peers and professionals? I promise to bring my best listening ear :-). For now, I also suggest leaving it to the detailed and possibly useful comment (at least to some) that you've already taken the time to post instead of escalating further, but I'm fine either way I suppose.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
14,719
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
340
Comments
10
Likes
26
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. Spring and Java EE Side by Side Reza Rahman Java EE/GlassFish Evangelist Reza.Rahman@Oracle.com @reza_rahman
  • 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public2 Program Agenda  Spring and Java EE  Side-by-Side  Ecosystems
  • 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3 A Bird’s Eye View
  • 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4 Main Features/APIs • Spring also integrates with EJB 3, but not CDI • Similar patterns for validation, WebSocket, JSON, XML, SOAP, remoting, scheduling, caching, etc
  • 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5 Java EE and Spring Component @Stateless public class BidService { @PersistenceContext private EntityManager entityManager; public void addBid(Bid bid) { entityManager.persist(bid); } } @Component public class BidService { @PersistenceContext private EntityManager entityManager; @Transactional public void addBid(Bid bid) { entityManager.persist(bid); } }
  • 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6 Spring Bootstrap (XML) <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.actionbazaar"/> <tx:annotation-driven/> ... <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> </property> </bean> </beans>
  • 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7 Defining the Data Source <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:1521:actionbazaar"/> <property name="user" value="scott"/> <property name="password" value="tiger"/> </bean> <data-source> <name>java:global/jdbc/myDataSource</name> <class-name>oracle.jdbc.driver.OracleDriver</class-name> <port-number>1521</port-number> <server-name>localhost</server-name> <database-name>actionbazaar</database-name> <user>scott</user> <password>tiger</password> <property> <name>createDatabase</name> <value>create</value> </property> </data-source>
  • 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8 Spring Bootstrap (Java) @Configuration @ComponentScan(basePackages="com.actionbazaar") @EnableTransactionManagement public class DataConfiguration { @Bean(destroyMethod="close") public DataSource dataSource(){ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); ds.setUrl("jdbc:oracle:thin:@localhost:1521:actionbazaar"); ds.setUser("scott"); ds.setPassword("tiger"); return ds; } @Bean public PlatformTransactionManager transactionManager(){ return new DataSourceTransactionManager(dataSource()); } @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ LocalContainerEntityManagerFactoryBean factory = LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); return factory; } }
  • 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9 Servlet Bootstrap <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:**/applicationContext*.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ... </web-app>
  • 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10 Simple JSF Page <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <ui:composition template="/WEB-INF/template.xhtml"> <ui:define name="title">Add Bid</ui:define> <ui:define name="content"> <h3>Add Bid</h3> <h:form> <p>Item: <h:outputText value="#{item.name}"/></p> <p>Current bid: <h:outputText value="#{item.highestBid.amount}"/></p> <p>Amount: <h:inputText id="amount" value="#{bid.amount}"/></p> <p><h:commandButton value="Add bid" action="#{addBid.onClick}"/></p> </h:form> </ui:define> </ui:composition> </html>
  • 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11 CDI/JPA Components CDI Backing Bean JPA Entity @Named @ViewScoped public class AddBid { @Inject private BidService bidService; @Inject @LoggedIn private User user; @Inject @SelectedItem private Item item; @Produces @Named private Bid bid = new Bid(); public String onClick() { bid.setBidder(user); bid.setItem(item); bidService.addBid(bid); return “bid_confirm.xhtml”; } } @Entity @Table(name="BIDS") public class Bid { @Id @GeneratedValue private long id; @ManyToOne(optional=false) private User bidder; @ManyToOne(optional=false) private Item item; DecimalMin("0.0") private double amount; ... }
  • 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12 Servlet Bootstrap <web-app> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> </web-app>
  • 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13 Spring MVC JSP Page <%@ taglib prefix="tiles“ uri="http://tiles.apache.org/tags-tiles" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <tiles:insertDefinition name="defaultTemplate"> <tiles:putAttribute name=“title">Add Bid</tiles:putAttribute> <tiles:putAttribute name=“content"> <h3>Add Bid</h3> <form:form modelAttribute="bid" method="post"> <p>Item: <form:errors path="item" cssClass="error"/> ${item.name}</p> <p>Current bid: ${item.highestBid.amount}</p> <p>Amount: <form:errors path="amount" cssClass="error"/> <form:input path="amount"/></p> <p><input type="submit" value="Add Bid"> </form:form> </tiles:putAttribute> </tiles:insertDefinition>
  • 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14 Spring MVC Controller @RequestMapping("/add_bid.do") @SessionAttributes({"item", "bid"}) public class BidController { @Autowired private ItemService itemService; @Autowired private BidService bidService; @RequestMapping(method=RequestMethod.GET) public String setupForm(@RequestParam("itemId") int itemId, ModelMap model) { Item item = itemService.getItem(itemId); model.addAttribute("item", item); Bid bid = new Bid(); model.addAttribute("bid", bid); return "add_bid"; } @RequestMapping(method=RequestMethod.POST) public String addBid(@ModelAttribute("item") Item item, @Valid @ModelAttribute("bid") Bid bid, HttpSession session, BindingResult result, SessionStatus status) { bid.setBidder((User)session.getAttribute("user")); bid.setItem(item); if (result.hasErrors()) { return "add_bid"; } else { bidService.addBid(bid); status.setComplete(); return "redirect:confirm_bid.do?itemId=" + item.getItemId(); } } }
  • 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public15 Spring MVC Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com.actionbazaar"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles/tiles-definitions.xml</value> </list> </property> </bean> </beans>
  • 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16 Servlet Bootstrap <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:**/applicationContext*.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>actionbazaar</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>actionbazaar</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>jsp/index.jsp</welcome-file> </welcome-file-list> </web-app>
  • 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public17 CDI Interceptor @Stateless public class BidService { @Inject private BidRepository bidRepository; ... @Audited public void addBid(Bid bid) { ... bidRepository.saveBid(bid); } } @Interceptor @Audited public class AuditInterceptor { @AroundInvoke public Object audit(InvocationContext context) { logger.log(Level.INFO, "Executing: {0}", context.getMethod().getName()); return context.proceed(); } } @InterceptorBindingType @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface Audited {}
  • 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public18 Spring/AspectJ @Component public class BidService { @Autowired private BidRepository bidRepository; ... @Audited @Transactional public void addBid(Bid bid) { ... bidRepository.saveBid(bid); } } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Audited {} @Component @Aspect public class AuditAspect { @Before("execution(public * *(..)) && @annotation(Audited)") public void audit(JoinPoint joinPoint) { logger.log(Level.INFO, "Entering: {0}", joinPoint); } }
  • 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public19 Spring/AspectJ Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> ... <aop:aspectj-autoproxy/> ... </beans>
  • 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public20 JMS MDB @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:global/jms/OrderQueue")}) public class OrderProcessor implements MessageListener { @Inject private OrderService orderService; public void onMessage(Message message) { try { ObjectMessage objectMessage = (ObjectMessage) message; Order order = (Order) objectMessage.getObject(); orderService.addOrder(order); } catch (JMSException e) { e.printStackTrace(); } } } <jms-destination> <name>java:global/jms/OrderQueue</name> <interface-name>javax.jms.Queue</interface-name> <resource-adapter>jmsra</resource-adapter> <destination-name>OrderQueue</destination-name> </jms-destination>
  • 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public21 Spring JMS Listener @Component public class OrderProcessor implements MessageListener { @Autowired private OrderService orderService; @Transactional public void onMessage(Message message) { try { ObjectMessage objectMessage = (ObjectMessage) message; Order order = (Order) objectMessage.getObject(); orderService.addOrder(order); } catch (JMSException e) { e.printStackTrace(); } } }
  • 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public22 Spring Message Listener Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> ... <amq:broker useJmx="false" persistent="false"> <amq:transportConnectors> <amq:transportConnector uri="tcp://localhost:0" /> </amq:transportConnectors> </amq:broker> <amq:queue id="jms/OrderQueue" physicalName="queue.OrderQueue"/> <amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/> <jms:listener-container transaction-manager="transactionManager" concurrency="3-5"> <jms:listener destination="jms/OrderQueue" ref="orderProcessor"/> </jms:listener-container> </beans>
  • 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public23 JMS 2 Message Sender @Stateless public class OrderService { @Inject private JMSContext jmsContext; @Resource(lookup = "java:global/jms/OrderQueue") private Destination orderQueue; ... public void sendOrder(Order order) { jmsContext.createProducer() .setPriority(HIGH_PRIORITY) .setDisableMessageID(true) .setDisableMessageTimestamp(true) .send(orderQueue, order); } }
  • 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public24 Spring JMS Message Sender @Component public class OrderService { private JmsTemplate jmsTemplate; @Resource(name="jms/OrderQueue") private Queue queue; ... @Autowired public void setConnectionFactory( ConnectionFactory connectionFactory) { jmsTemplate = new JmsTemplate(connectionFactory); } @Transactional public void sendOrder(Order order) { jmsTemplate.setExplicitQosEnabled(true); jmsTemplate.setPriority(HIGH_PRIORITY); jmsTemplate.setMessageIdEnabled(false); jmsTemplate.setMessageTimestampEnabled(false); jmsTemplate.convertAndsend(queue, order); } }
  • 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public25 EJB3 and Spring Scheduling @Stateless public class NewsLetterGenerator { ... @Schedule(dayOfMonth="Last Tues", month="Jan-May, Sep-Nov", timezone="America/New_York") public void generateMonthlyNewsLetter() { ... } } @Component public class NewsLetterGenerator { ... @Scheduled( cron="0 0 0 ? JAN-MAY,SEP-NOV 3L") public void generateMonthlyNewsLetter() { ... } }
  • 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public26 Spring Scheduling Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"> ... <task:annotation-driven scheduler="myScheduler"/> <task:scheduler id="myScheduler" pool-size="10"/> </beans>
  • 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public27 Spring Projects
  • 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public28 Java EE Ecosystem
  • 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public29 CDI Ecosystem Implementations Weld CanDI RuntimesPortable Extensions Tools
  • 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public30 CDI Extensions
  • 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public31 Decisions, decisions…
  • 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public32 A Bird’s Eye View

×