Hi all
I'm trying to make an application that has an embedded webserver for remote monitoring/interaction.
Following some tutorials and posts I've found on this forum I was able to start a jetty webserver with spring security and a stub controller.
This is the context that launch the jetty server
web.xmlHTML Code:<?xml version="1.0" encoding="UTF-8"?> <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:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" > <!-- This bean will be available for injection in the child context that the Web Service is in. --> <!--<context:property-placeholder location="org/springbyexample/ws/embedded/ws.properties"/>--> <!-- Manually start server after setting parent context. (init-method="start") --> <bean id="jettyServer" class="org.mortbay.jetty.Server" destroy-method="stop"> <property name="threadPool"> <bean id="ThreadPool" class="org.mortbay.thread.QueuedThreadPool"> <property name="minThreads" value="2"/> <property name="maxThreads" value="10"/> </bean> </property> <property name="connectors"> <list> <bean id="Connector" class="org.mortbay.jetty.nio.SelectChannelConnector" p:maxIdleTime="30000" p:acceptors="2" p:confidentialPort="8443"> <property name="port"> <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean" p:targetBeanName="config" p:propertyPath="port"/> </property> </bean> </list> </property> <property name="handlers"> <list> <bean name="webapp" class="org.mortbay.jetty.webapp.WebAppContext"> <property name="contextPath" value="/"/> <property name="server" ref="jettyServer"/> <property name="resourceBase"> <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean" p:targetBeanName="config" p:propertyPath="webappLocation"/> </property> </bean> </list> </property> </bean> </beans>
Static mainHTML Code:<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>CluKep</display-name> <description>Cluster Keeper</description> <context-param> <param-name>webAppRootKey</param-name> <param-value>clukepwebapp</param-value> </context-param> <!-- Log4j have to be the first to log all the other listeners. --> <!-- <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.xml</param-value> </context-param>--> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Spring Security Context --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>clukep</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet-mapping> <servlet-name>clukep</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/clukep-servlet.xml /WEB-INF/clukep-security.xml </param-value> </context-param> <distributable /> </web-app>
Code:public static void main(String[] args) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); // Define a bean with the command line parameters and register it BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(Arrays.class, "asList").addConstructorArgValue(args).getBeanDefinition(); beanFactory.registerBeanDefinition("cmdArgs", beanDefinition); GenericApplicationContext cmdArgCxt = new GenericApplicationContext(beanFactory); // Must call refresh to initialize context cmdArgCxt.refresh(); ApplicationContext ac = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS, cmdArgCxt); Server server = (Server) ac.getBean("jettyServer"); try { server.start(); } catch (Exception ex) { java.util.logging.Logger.getLogger(ClukepServerMain.class.getName()).log(Level.SEVERE, null, ex); } ServerEngine se = (ServerEngine) ac.getBean("serverEngine"); se.run(); }
Now how can I make the beans of the context of the web xml see the beans on the server context?
Thank You


Reply With Quote