Contenu connexe Similaire à Java EE 6 CDI Integrates with Spring & JSF Similaire à Java EE 6 CDI Integrates with Spring & JSF (20) Java EE 6 CDI Integrates with Spring & JSF1. Java EE 6 CDI Integrates
with Spring & JSF
on Java EE 5
Jiayun Zhou jiayun@jiayun.org
2012/03/17
TWJUG
13. GUI
require 'tk'
root = TkRoot.new()
name_label = TkLabel.new() {text "What is Your Name?"}
name_label.pack
name = TkEntry.new(root).pack
name.bind("FocusOut") {process_name(name)}
quest_label = TkLabel.new() {text "What is Your Quest?"}
quest_label.pack
quest = TkEntry.new(root).pack
quest.bind("FocusOut") {process_quest(quest)}
Tk.mainloop()
13
18. class MovieLister...
public Movie[] moviesDirectedBy(String arg) {
List allMovies = finder.findAll();
for (Iterator it = allMovies.iterator(); it.hasNext();) {
Movie movie = (Movie) it.next();
if (!movie.getDirector().equals(arg)) it.remove();
}
return (Movie[]) allMovies.toArray(new
Movie[allMovies.size()]);
}
18
32. Libraries
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.myfaces.extensions.cdi.bundles</groupId>
<artifactId>myfaces-extcdi-bundle-jsf20</artifactId>
</dependency>
<dependency>
<groupId>org.apache.myfaces.extensions.cdi.modules.jee5-support</groupId>
<artifactId>myfaces-extcdi-jee5-weld-support</artifactId>
<scope>runtime</scope>
</dependency>
33. Libraries
<dependency>
<groupId>org.cdisource.springbridge</groupId>
<artifactId>springbridge</artifactId>
</dependency>
<dependency>
<groupId>org.cdisource.beancontainer</groupId>
<artifactId>beancontainer-weld-impl</artifactId>
</dependency>
34. web.xml
<listener>
<listener-
class>org.cdisource.springintegration.servletsupport.ApplicationC
ontextFinderServletContextListener</listener-class>
</listener>
<listener>
<listener-
class>org.apache.myfaces.extensions.cdi.weld.startup.WeldAwareCon
figurationListener</listener-class>
</listener>
35. beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
• src/main/webapp/WEB-INF
• src/main/resources
都要放
36. Spring Bridge
• src/main/resources/META-
INF/services/javax.enterprise.inject.spi.Extension
• 內容:
org.cdisource.springintegration.SpringIntegration
Extention
• Service Provider Interface (SPI)
http://docs.oracle.com/javase/7/docs/api/java/
util/ServiceLoader.html
37. Spring 掃描排除 CDI Bean
<context:component-scan base-
package="com.xxx">
<context:exclude-filter type="regex"
expression="com.xxx.*.web.*" />
</context:component-scan>