Updated jetty-spring module.

This commit is contained in:
Simone Bordet 2012-11-20 17:33:34 +01:00
parent dd180a8c48
commit a5df0ab456
13 changed files with 203 additions and 300 deletions

View File

@ -1,5 +0,0 @@
This jetty module is an example of how spring can be used to
configure and run Jetty.

View File

@ -9,7 +9,7 @@
<name>Example :: Jetty Spring</name> <name>Example :: Jetty Spring</name>
<properties> <properties>
<spring-version>2.5.6</spring-version> <spring-version>3.1.3.RELEASE</spring-version>
<dependencies>target/dependencies</dependencies> <dependencies>target/dependencies</dependencies>
</properties> </properties>
@ -38,24 +38,25 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId> <artifactId>jetty-xml</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId> <artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring</artifactId> <artifactId>spring-beans</artifactId>
<version>${spring-version}</version> <version>${spring-version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId> <artifactId>jetty-test-helper</artifactId>

View File

@ -5,32 +5,24 @@
<!-- Configure the Jetty Server with Spring --> <!-- Configure the Jetty Server with Spring -->
<!-- This file is the similar to jetty.xml, but written in spring --> <!-- This file is the similar to jetty.xml, but written in spring -->
<!-- XmlBeanFactory format. --> <!-- XmlBeanFactory format. -->
<!-- -->
<!-- This file may be run with: -->
<!-- java -jar start.jar OPTIONS=Server,spring \ -->
<!-- start.class=org.eclipse.jetty.spring.Main \ -->
<!-- etc/jetty-spring.xml -->
<!-- -->
<!-- The spring and commons-logging jars may need to be added -->
<!-- to the classpath -->
<!-- =============================================================== --> <!-- =============================================================== -->
<beans> <beans>
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/> <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server" init-method="start" destroy-method="stop"> <bean id="server" name="Main" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">
<constructor-arg>
<property name="threadPool"> <bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10"/> <property name="minThreads" value="10"/>
<property name="maxThreads" value="50"/> <property name="maxThreads" value="50"/>
</bean> </bean>
</property> </constructor-arg>
<property name="connectors"> <property name="connectors">
<list> <list>
<bean id="Connector" class="org.eclipse.jetty.server.ServerConnector"> <bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg ref="server"/>
<property name="port" value="8080"/> <property name="port" value="8080"/>
</bean> </bean>
</list> </list>
@ -49,25 +41,18 @@
<property name="beans"> <property name="beans">
<list> <list>
<bean id="ContextDeployer" class="org.eclipse.jetty.deploy.ContextDeployer"> <bean id="deploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<property name="contexts" ref="contexts"/> <property name="contexts" ref="contexts"/>
<property name="directory" value="contexts"/> <property name="appProviders">
<property name="scanInterval" value="5"/> <list>
<bean id="webAppProvider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<property name="monitoredDirName" value="webapps"/>
<property name="scanInterval" value="1"/>
<property name="extractWars" value="true"/>
</bean> </bean>
</list>
<bean id="WebAppDeployer" class="org.eclipse.jetty.deploy.WebAppDeployer"> </property>
<property name="contexts" ref="contexts"/>
<property name="webAppDir" value="webapps"/>
<property name="extract" value="true"/>
<property name="defaultsDescriptor" value="etc/webdefault.xml"/>
</bean> </bean>
<bean class="org.eclipse.jetty.security.HashLoginService">
<property name="name" value="Test Realm"/>
<property name="config" value="etc/realm.properties"/>
<property name="refreshInterval" value="0"/>
</bean>
</list> </list>
</property> </property>

View File

@ -16,23 +16,19 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.spring; package org.eclipse.jetty.spring;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
/**
/* ------------------------------------------------------------ */ * Runs Jetty from a Spring configuration file passed as argument.
/** Run Jetty from Spring configuration.
* @see <a href="http://svn.codehaus.org/jetty/jetty/trunk/jetty-spring/src/main/config/etc/jetty-spring.xml">jetty-spring.xml</a>
*/ */
public class Main public class Main
{ {
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
Resource config = Resource.newResource(args.length == 1?args[0]:"src/main/config/etc/jetty-spring.xml"); Resource config = Resource.newResource(args.length == 1 ? args[0] : "etc/jetty-spring.xml");
XmlConfiguration.main(new String[]{config.getFile().getAbsolutePath()}); XmlConfiguration.main(config.getFile().getAbsolutePath());
} }
} }

View File

@ -1,61 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.spring;
import java.net.InetSocketAddress;
import java.util.Collection;
import org.eclipse.jetty.util.thread.ThreadPool;
/* ------------------------------------------------------------ */
/**
* Convenience class for jetty with Spring.
* This class provides a setBeans method as an alternate
* access to the {@link #addBean(Object)} API.
*/
public class Server extends org.eclipse.jetty.server.Server
{
public Server()
{
super();
}
public Server(InetSocketAddress addr)
{
super(addr);
}
public Server(int port)
{
super(port);
}
public Server(ThreadPool pool)
{
super(pool);
}
public void setBeans(Collection<Object> beans)
{
for (Object o:beans)
addBean(o);
}
}

View File

@ -22,7 +22,9 @@ package org.eclipse.jetty.spring;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.xml.ConfigurationProcessor; import org.eclipse.jetty.xml.ConfigurationProcessor;
import org.eclipse.jetty.xml.ConfigurationProcessorFactory; import org.eclipse.jetty.xml.ConfigurationProcessorFactory;
@ -35,48 +37,50 @@ import org.springframework.core.io.UrlResource;
/** /**
* Spring ConfigurationProcessor * Spring ConfigurationProcessor
* <p> * <p/>
* A {@link ConfigurationProcessor} that uses a spring XML file to emulate the {@link XmlConfiguration} format. * A {@link ConfigurationProcessor} that uses a spring XML file to emulate the {@link XmlConfiguration} format.
* <p> * <p/>
* {@link XmlConfiguration} expects a primary object that is either passed in to a call to {@link #configure(Object)} * {@link XmlConfiguration} expects a primary object that is either passed in to a call to {@link #configure(Object)}
* or that is constructed by a call to {@link #configure()}. This processor looks for a bean definition * or that is constructed by a call to {@link #configure()}. This processor looks for a bean definition
* with an id, name or alias of "Main" as uses that as the primary bean. * with an id, name or alias of "Main" as uses that as the primary bean.
* <p> * <p/>
* The objects mapped by {@link XmlConfiguration#getIdMap()} are set as singletons before any configuration calls * The objects mapped by {@link XmlConfiguration#getIdMap()} are set as singletons before any configuration calls
* and if the spring configuration file contains a definition for the singleton id, the the singleton is updated * and if the spring configuration file contains a definition for the singleton id, the the singleton is updated
* with a call to {@link XmlBeanFactory#configureBean(Object, String)}. * with a call to {@link XmlBeanFactory#configureBean(Object, String)}.
* <p> * <p/>
* The property map obtained via {@link XmlConfiguration#getProperties()} is set as a singleton called "properties" * The property map obtained via {@link XmlConfiguration#getProperties()} is set as a singleton called "properties"
* and values can be accessed by somewhat verbose * and values can be accessed by somewhat verbose
* usage of {@link org.springframework.beans.factory.config.MethodInvokingFactoryBean}. * usage of {@link org.springframework.beans.factory.config.MethodInvokingFactoryBean}.
* <p> * <p/>
* This processor is returned by the {@link SpringConfigurationProcessorFactory} for any XML document whos first * This processor is returned by the {@link SpringConfigurationProcessorFactory} for any XML document whos first
* element is "beans". The factory is discovered by a {@link ServiceLoader} for {@link ConfigurationProcessorFactory}. * element is "beans". The factory is discovered by a {@link ServiceLoader} for {@link ConfigurationProcessorFactory}.
*/ */
public class SpringConfigurationProcessor implements ConfigurationProcessor public class SpringConfigurationProcessor implements ConfigurationProcessor
{ {
static final Logger __log = org.eclipse.jetty.util.log.Log.getLogger(SpringConfigurationProcessor.class.getName()); private static final Logger LOG = Log.getLogger(SpringConfigurationProcessor.class);
Map<String, Object> _idMap; private Map<String, Object> _idMap;
Map<String, String> _propertyMap; private Map<String, String> _propertyMap;
XmlBeanFactory _beanFactory; private XmlBeanFactory _beanFactory;
String _main; private String _main;
public void init(URL url, XmlParser.Node config, Map<String, Object> idMap, Map<String, String> properties) public void init(URL url, XmlParser.Node config, Map<String, Object> idMap, Map<String, String> properties)
{ {
try try
{ {
_idMap=idMap; _idMap = idMap;
_propertyMap=properties; _propertyMap = properties;
Resource resource = (url!=null) Resource resource = url != null
?new UrlResource(url) ? new UrlResource(url)
:new ByteArrayResource(("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">"+config).getBytes("UTF-8")); : new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
_beanFactory=new XmlBeanFactory(resource); "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
config).getBytes("UTF-8"));
_beanFactory = new XmlBeanFactory(resource);
} }
catch(Exception e) catch (Exception e)
{ {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -85,11 +89,12 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
public Object configure(Object obj) throws Exception public Object configure(Object obj) throws Exception
{ {
doConfigure(); doConfigure();
return _beanFactory.configureBean(obj,_main); return _beanFactory.configureBean(obj, _main);
} }
/** /**
* Return a configured bean. If a bean has the id or alias of "Main", then it is returned, otherwise the first bean in the file is returned. * Return a configured bean. If a bean has the id or alias of "Main", then it is returned, otherwise the first bean in the file is returned.
*
* @see org.eclipse.jetty.xml.ConfigurationProcessor#configure() * @see org.eclipse.jetty.xml.ConfigurationProcessor#configure()
*/ */
public Object configure() throws Exception public Object configure() throws Exception
@ -100,28 +105,28 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
private void doConfigure() private void doConfigure()
{ {
_beanFactory.registerSingleton("properties",_propertyMap); _beanFactory.registerSingleton("properties", _propertyMap);
// Look for the main bean; // Look for the main bean;
for (String bean : _beanFactory.getBeanDefinitionNames()) for (String bean : _beanFactory.getBeanDefinitionNames())
{ {
__log.debug("{} - {}",bean,Arrays.asList(_beanFactory.getAliases(bean))); LOG.debug("{} - {}", bean, Arrays.asList(_beanFactory.getAliases(bean)));
String[] aliases = _beanFactory.getAliases(bean); String[] aliases = _beanFactory.getAliases(bean);
if ("Main".equals(bean) || aliases!=null && Arrays.asList(aliases).contains("Main")) if ("Main".equals(bean) || aliases != null && Arrays.asList(aliases).contains("Main"))
{ {
_main=bean; _main = bean;
break; break;
} }
} }
if (_main==null) if (_main == null)
_main=_beanFactory.getBeanDefinitionNames()[0]; _main = _beanFactory.getBeanDefinitionNames()[0];
// Register id beans as singletons // Register id beans as singletons
__log.debug("idMap {}",_idMap); LOG.debug("idMap {}", _idMap);
for (String id : _idMap.keySet()) for (String id : _idMap.keySet())
{ {
__log.debug("register {}",id); LOG.debug("register {}", id);
_beanFactory.registerSingleton(id,_idMap.get(id)); _beanFactory.registerSingleton(id, _idMap.get(id));
} }
// Apply configuration to existing singletons // Apply configuration to existing singletons
@ -129,13 +134,13 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
{ {
if (_beanFactory.containsBeanDefinition(id)) if (_beanFactory.containsBeanDefinition(id))
{ {
__log.debug("reconfigure {}",id); LOG.debug("reconfigure {}", id);
_beanFactory.configureBean(_idMap.get(id),id); _beanFactory.configureBean(_idMap.get(id), id);
} }
} }
// Extract id's for next time. // Extract id's for next time.
for (String id : _beanFactory.getSingletonNames()) for (String id : _beanFactory.getSingletonNames())
_idMap.put(id,_beanFactory.getBean(id)); _idMap.put(id, _beanFactory.getBean(id));
} }
} }

View File

@ -16,7 +16,6 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.spring; package org.eclipse.jetty.spring;
import org.eclipse.jetty.xml.ConfigurationProcessor; import org.eclipse.jetty.xml.ConfigurationProcessor;
@ -25,12 +24,12 @@ import org.eclipse.jetty.xml.XmlConfiguration;
/** /**
* Spring ConfigurationProcessor Factory * Spring ConfigurationProcessor Factory
* <p> * <p/>
* Create a {@link SpringConfigurationProcessor} for XML documents with a "beans" element. * Create a {@link SpringConfigurationProcessor} for XML documents with a "beans" element.
* The factory is discovered by a {@link ServiceLoader} for {@link ConfigurationProcessorFactory}. * The factory is discovered by a {@link java.util.ServiceLoader} for {@link ConfigurationProcessorFactory}.
*
* @see SpringConfigurationProcessor * @see SpringConfigurationProcessor
* @see XmlConfiguration * @see XmlConfiguration
*
*/ */
public class SpringConfigurationProcessorFactory implements ConfigurationProcessorFactory public class SpringConfigurationProcessorFactory implements ConfigurationProcessorFactory
{ {

View File

@ -24,13 +24,13 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
import org.junit.Assert;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SpringXmlConfigurationTest public class SpringXmlConfigurationTest
{ {
protected String _configure="org/eclipse/jetty/spring/configure.xml"; protected String _configure="org/eclipse/jetty/spring/configure.xml";
@ -60,7 +60,7 @@ public class SpringXmlConfigurationTest
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
XmlConfiguration configuration = new XmlConfiguration(url); XmlConfiguration configuration = new XmlConfiguration(url);
Map<String,String> properties = new HashMap<String,String>(); Map<String,String> properties = new HashMap<>();
properties.put("test", "xxx"); properties.put("test", "xxx");
TestConfiguration nested = new TestConfiguration(); TestConfiguration nested = new TestConfiguration();
@ -74,20 +74,20 @@ public class SpringXmlConfigurationTest
tc=(TestConfiguration)configuration.configure(tc); tc=(TestConfiguration)configuration.configure(tc);
assertEquals("preconfig",tc.getTestString0()); Assert.assertEquals("preconfig", tc.getTestString0());
assertEquals(42,tc.getTestInt0()); Assert.assertEquals(42, tc.getTestInt0());
assertEquals("SetValue",tc.getTestString1()); Assert.assertEquals("SetValue", tc.getTestString1());
assertEquals(1,tc.getTestInt1()); Assert.assertEquals(1, tc.getTestInt1());
assertEquals("nested",tc.getNested().getTestString0()); Assert.assertEquals("nested", tc.getNested().getTestString0());
assertEquals("nested",tc.getNested().getTestString1()); Assert.assertEquals("nested", tc.getNested().getTestString1());
assertEquals("default",tc.getNested().getNested().getTestString0()); Assert.assertEquals("default", tc.getNested().getNested().getTestString0());
assertEquals("deep",tc.getNested().getNested().getTestString1()); Assert.assertEquals("deep", tc.getNested().getNested().getTestString1());
assertEquals("deep",((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1()); Assert.assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
assertEquals(2,((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2()); Assert.assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
assertEquals("xxx",tc.getTestString2()); Assert.assertEquals("xxx", tc.getTestString2());
} }
@Test @Test
@ -98,7 +98,7 @@ public class SpringXmlConfigurationTest
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
XmlConfiguration configuration = new XmlConfiguration(url); XmlConfiguration configuration = new XmlConfiguration(url);
Map<String,String> properties = new HashMap<String,String>(); Map<String,String> properties = new HashMap<>();
properties.put("test", "xxx"); properties.put("test", "xxx");
TestConfiguration nested = new TestConfiguration(); TestConfiguration nested = new TestConfiguration();
@ -108,20 +108,20 @@ public class SpringXmlConfigurationTest
configuration.getProperties().putAll(properties); configuration.getProperties().putAll(properties);
TestConfiguration tc = (TestConfiguration)configuration.configure(); TestConfiguration tc = (TestConfiguration)configuration.configure();
assertEquals("default",tc.getTestString0()); Assert.assertEquals("default", tc.getTestString0());
assertEquals(-1,tc.getTestInt0()); Assert.assertEquals(-1, tc.getTestInt0());
assertEquals("SetValue",tc.getTestString1()); Assert.assertEquals("SetValue", tc.getTestString1());
assertEquals(1,tc.getTestInt1()); Assert.assertEquals(1, tc.getTestInt1());
assertEquals("nested",tc.getNested().getTestString0()); Assert.assertEquals("nested", tc.getNested().getTestString0());
assertEquals("nested",tc.getNested().getTestString1()); Assert.assertEquals("nested", tc.getNested().getTestString1());
assertEquals("default",tc.getNested().getNested().getTestString0()); Assert.assertEquals("default", tc.getNested().getNested().getTestString0());
assertEquals("deep",tc.getNested().getNested().getTestString1()); Assert.assertEquals("deep", tc.getNested().getNested().getTestString1());
assertEquals("deep",((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1()); Assert.assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
assertEquals(2,((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2()); Assert.assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
assertEquals("xxx",tc.getTestString2()); Assert.assertEquals("xxx", tc.getTestString2());
} }
@Test @Test
@ -133,13 +133,11 @@ public class SpringXmlConfigurationTest
Server server = (Server)configuration.configure(); Server server = (Server)configuration.configure();
server.dumpStdErr(); server.dumpStdErr();
} }
@Test @Test
public void XmlConfigurationMain() throws Exception public void XmlConfigurationMain() throws Exception
{ {
XmlConfiguration.main(new String[]{"src/test/resources/org/eclipse/jetty/spring/jetty.xml"}); XmlConfiguration.main("src/test/resources/org/eclipse/jetty/spring/jetty.xml");
} }
} }

View File

@ -25,13 +25,13 @@ import org.junit.Ignore;
@Ignore @Ignore
public class TestConfiguration public class TestConfiguration
{ {
public static int VALUE=77; public static int VALUE = 77;
public TestConfiguration nested; public TestConfiguration nested;
public String testString0="default"; public String testString0 = "default";
public String testString1; public String testString1;
public String testString2; public String testString2;
public int testInt0=-1; public int testInt0 = -1;
public int testInt1; public int testInt1;
public int testInt2; public int testInt2;
public URL url; public URL url;
@ -43,6 +43,7 @@ public class TestConfiguration
{ {
return VALUE; return VALUE;
} }
public static void setVALUE(int vALUE) public static void setVALUE(int vALUE)
{ {
VALUE = vALUE; VALUE = vALUE;
@ -56,82 +57,99 @@ public class TestConfiguration
{ {
return nested; return nested;
} }
public void setNested(TestConfiguration nested) public void setNested(TestConfiguration nested)
{ {
this.nested = nested; this.nested = nested;
} }
public String getTestString0() public String getTestString0()
{ {
return testString0; return testString0;
} }
public void setTestString0(String testString0) public void setTestString0(String testString0)
{ {
this.testString0 = testString0; this.testString0 = testString0;
} }
public String getTestString1() public String getTestString1()
{ {
return testString1; return testString1;
} }
public void setTestString1(String testString1) public void setTestString1(String testString1)
{ {
this.testString1 = testString1; this.testString1 = testString1;
} }
public String getTestString2() public String getTestString2()
{ {
return testString2; return testString2;
} }
public void setTestString2(String testString2) public void setTestString2(String testString2)
{ {
this.testString2 = testString2; this.testString2 = testString2;
} }
public int getTestInt0() public int getTestInt0()
{ {
return testInt0; return testInt0;
} }
public void setTestInt0(int testInt0) public void setTestInt0(int testInt0)
{ {
this.testInt0 = testInt0; this.testInt0 = testInt0;
} }
public int getTestInt1() public int getTestInt1()
{ {
return testInt1; return testInt1;
} }
public void setTestInt1(int testInt1) public void setTestInt1(int testInt1)
{ {
this.testInt1 = testInt1; this.testInt1 = testInt1;
} }
public int getTestInt2() public int getTestInt2()
{ {
return testInt2; return testInt2;
} }
public void setTestInt2(int testInt2) public void setTestInt2(int testInt2)
{ {
this.testInt2 = testInt2; this.testInt2 = testInt2;
} }
public URL getUrl() public URL getUrl()
{ {
return url; return url;
} }
public void setUrl(URL url) public void setUrl(URL url)
{ {
this.url = url; this.url = url;
} }
public Object[] getObjArray() public Object[] getObjArray()
{ {
return objArray; return objArray;
} }
public void setObjArray(Object[] objArray) public void setObjArray(Object[] objArray)
{ {
this.objArray = objArray; this.objArray = objArray;
} }
public int[] getIntArray() public int[] getIntArray()
{ {
return intArray; return intArray;
} }
public void setIntArray(int[] intArray) public void setIntArray(int[] intArray)
{ {
this.intArray = intArray; this.intArray = intArray;
} }
} }

View File

@ -8,26 +8,26 @@
<!-- extract a value from the property map --> <!-- extract a value from the property map -->
<bean id="testProperty" singleton="false" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <bean id="testProperty" singleton="false" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject"><ref local="properties" /></property> <property name="targetObject"><ref local="properties" /></property>
<property name="targetMethod"><value>get</value></property> <property name="targetMethod" value="get" />
<property name="arguments"><list><value>test</value></list></property> <property name="arguments"><list><value>test</value></list></property>
</bean> </bean>
<bean id="root" name="Some,Names,Main" class="org.eclipse.jetty.spring.TestConfiguration"> <bean id="root" name="Some,Names,Main" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testString1"><value>SetValue</value></property> <property name="testString1" value="SetValue" />
<property name="testInt1"><value>1</value></property> <property name="testInt1" value="1" />
<property name="nested" ref="nested"/> <property name="nested" ref="nested" />
<property name="testString2" ref="testProperty"/> <property name="testString2" ref="testProperty"/>
</bean> </bean>
<bean id="nested" class="org.eclipse.jetty.spring.TestConfiguration"> <bean id="nested" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testInt2"><value>2</value></property> <property name="testInt2" value="2" />
<property name="testString1"><value>nested</value></property> <property name="testString1" value="nested" />
<property name="nested" ref="nestedDeep"/> <property name="nested" ref="nestedDeep" />
</bean> </bean>
<bean id="nestedDeep" class="org.eclipse.jetty.spring.TestConfiguration"> <bean id="nestedDeep" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testString1"><value>deep</value></property> <property name="testString1" value="deep" />
<property name="testInt2"><value>2</value></property> <property name="testInt2" value="2" />
</bean> </bean>
</beans> </beans>

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server">
<!--
<property name="beans">
<list>
<bean id="ContextDeployer" class="org.eclipse.jetty.spring.ContextDeployer">
<property name="contexts" ref="contexts"/>
<property name="contextsDir" value="contexts"/>
<property name="scanInterval" value="5"/>
</bean>
<bean id="WebAppDeployer" class="org.eclipse.jetty.deploy.WebAppDeployer">
<property name="contexts" ref="contexts"/>
<property name="webAppDir" value="webapps"/>
<property name="extract" value="true"/>
<property name="defaultsDescriptor" value="etc/webdefault.xml"/>
</bean>
<bean class="org.eclipse.jetty.security.HashLoginService">
<property name="name" value="Test Realm"/>
<property name="config" value="etc/realm.properties"/>
<property name="refreshInterval" value="0"/>
</bean>
</list>
</property>
-->
</bean>
</beans>

View File

@ -2,31 +2,29 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans> <beans>
<bean id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/> <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server"> <bean id="server" name="Main" class="org.eclipse.jetty.server.Server">
<constructor-arg type="org.eclipse.jetty.util.thread.ThreadPool"> <constructor-arg type="org.eclipse.jetty.util.thread.ThreadPool">
<bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool"> <bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10"/> <property name="minThreads" value="10"/>
<property name="maxThreads" value="200"/> <property name="maxThreads" value="200"/>
</bean> </bean>
</constructor-arg> </constructor-arg>
<!--
<property name="connectors"> <property name="connectors">
<list> <list>
<bean id="Connector" class="org.eclipse.jetty.server.ServerConnector"> <bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg type="org.eclipse.jetty.spring.Server"><ref bean="Server"/></constructor-arg> <constructor-arg type="org.eclipse.jetty.server.Server" ref="server" />
<property name="port" value="0"/> <property name="port" value="8080"/>
</bean> </bean>
</list> </list>
</property> </property>
-->
<property name="handler"> <property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers"> <property name="handlers">
<list> <list>
<ref bean="Contexts"/> <ref bean="contexts"/>
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/> <bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</list> </list>
</property> </property>

View File

@ -381,13 +381,18 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
} }
} }
@Override @Override
public Collection<Object> getBeans() public Collection<Object> getBeans()
{ {
return getBeans(Object.class); return getBeans(Object.class);
} }
public void setBeans(Collection<Object> beans)
{
for (Object bean : beans)
addBean(bean);
}
@Override @Override
public <T> Collection<T> getBeans(Class<T> clazz) public <T> Collection<T> getBeans(Class<T> clazz)
{ {