|
Size: 3155
Comment:
|
← Revision 4 as of 2009-09-20 23:20:14 ⇥
Size: 3157
Comment: converted to 1.6 markup
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| source: [attachment:mini_app.zip mini_app.zip(8kB)] | source: [[attachment:mini_app.zip|mini_app.zip(8kB)]] |
| Line 3: | Line 3: |
| Here is a simple example on how to use only tapestry-ioc in your app.[[BR]] | Here is a simple example on how to use only tapestry-ioc in your app.<<BR>> |
source: mini_app.zip(8kB)
Here is a simple example on how to use only tapestry-ioc in your app.
Using IOC has many advantages, so why not get used to it even in the smallest apps.
if you are comfortable with maven: pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>tapestry.mini-app</groupId>
<artifactId>mini-app</artifactId>
<version>0.0.1</version>
<build>
<finalName>mini-app</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-ioc</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
</dependencies>
<properties>
<tapestry-release-version>5.0.6</tapestry-release-version>
</properties>
</project>or add these libraries to your path
javassist-3.4.ga.jar log4j-1.2.14.jar tapestry-ioc-5.0.5.jar slf4j-api-1.4.3.jar slf4j-log4j12-1.4.3.jar
Your main class is fairly simple(Main.java)
1 package tapestry.mini;
2
3 import org.apache.tapestry.ioc.Registry;
4 import org.apache.tapestry.ioc.RegistryBuilder;
5
6 import tapestry.mini.services.Hello;
7 import tapestry.mini.services.MiniAppModule;
8
9 public class Main {
10
11 public static void main(String[] args) {
12 RegistryBuilder builder = new RegistryBuilder();
13 builder.add(MiniAppModule.class);
14
15 Registry registry = builder.build();
16 registry.performRegistryStartup();
17
18
19 Hello hello = registry.getService(Hello.class);
20 hello.sayHello();
21
22 //for operations done from this thread
23 registry.cleanupThread();
24 //call this to allow services clean shutdown
25 registry.shutdown();
26 }
27 }
MiniAppModule.java:
A small class that also shows automatic dependency injection: Hello.java
a very simple dependancy: Output.java
A simple implementation of course: OutputImpl.java