2011-06-19 38 views
0

我試圖將org.apache.commons.dbcp.BasicDataSource配置爲使用tomcat 6的tomcat項目下的web.xml中的bean。(這是使用tomcat的red5,我們可以忽略主服務器實際上是RED5,因爲我實際上運行在端口5080的jsp文件,也不要連接到RED5直接使用RTMP協議)將BasicDataSource配置爲web.xml中的bean

我的web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app 
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" 
version="2.4"> 

<display-name>gamesisland-login-red5</display-name> 

<context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>/[myapp]</param-value> 
</context-param> 

<listener> 
    <listener-class>org.red5.logging.ContextLoggingListener</listener-class> 
</listener> 

<filter> 
    <filter-name>LoggerContextFilter</filter-name> 
    <filter-class>org.red5.logging.LoggerContextFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>LoggerContextFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<servlet> 
    <servlet-name>rtmpt</servlet-name> 
    <servlet-class>org.red5.server.net.rtmpt.RTMPTServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>rtmpt</servlet-name> 
    <url-pattern>/fcs/*</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>rtmpt</servlet-name> 
    <url-pattern>/open/*</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>rtmpt</servlet-name> 
    <url-pattern>/close/*</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>rtmpt</servlet-name> 
    <url-pattern>/send/*</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>rtmpt</servlet-name> 
    <url-pattern>/idle/*</url-pattern> 
</servlet-mapping> 

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Forbidden</web-resource-name> 
     <url-pattern>/streams/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint/> 
</security-constraint> 

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value="/WEB-INF/red5-web.properties" /> 
</bean> 

    <bean id="idDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
      <property name="driverClassName"><value>${db.driver}</value></property> 
      <property name="url"><value>${db.url}</value></property> 
      <property name="username"><value>${db.username}</value></property> 
      <property name="password"><value>${db.password}</value></property> 
      <property name="poolPreparedStatements"><value>true</value></property> 
      <property name="maxActive"><value>10</value></property> 
      <property name="maxIdle"><value>10</value></property> 
    </bean> 


</web-app> 

我red5-web.properties :

webapp.contextPath=/myapp 
webapp.virtualHosts=* 
db.driver=com.mysql.jdbc.Driver 
db.url=jdbc:mysql://127.0.0.1:3306/dbname 
db.username=user 
db.password=pass 

tomcat是否自動搜索WEB-INF/web.xml進行配置?

爲什麼我不會在創建idDataSource時遇到任何相關的錯誤?

我真的沒有任何線索如何查明或調試問題。 任何援助將不勝感激。

謝謝!

幼獅

回答

4

我不知道任何關於Red5的,但好像你試圖把Spring bean的直接內web.xml,這是不對的。你可以創建一個單獨的Spring配置文件,該文件將被Springs的ContextLoaderListener選中。首先,添加到您的web.xml

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

/WEB-INF下創建applicationContext.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="location" value="/WEB-INF/red5-web.properties" /> 
    </bean> 

    <bean id="idDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
     <property name="driverClassName"><value>${db.driver}</value></property> 
     <property name="url"><value>${db.url}</value></property> 
     <property name="username"><value>${db.username}</value></property> 
     <property name="password"><value>${db.password}</value></property> 
     <property name="poolPreparedStatements"><value>true</value></property> 
     <property name="maxActive"><value>10</value></property> 
     <property name="maxIdle"><value>10</value></property> 
    </bean> 

</beans> 

當然所有<bean/>聲明應該從web.xml消失。

退一步:看着this文件好像Red5的使用名​​爲red5-web.xml文件,請仔細去通過這個文檔。

+0

當我使用rtmp協議連接到red5時,red5使用red5-web.xml。在這種情況下,我直接加載哪些常規tomcat服務器加載它們的頁面。你的信息看起來很棒!我一進辦公室就會檢查一下。 – ufk

+0

如何加載我在jsp頁面本身的applicationContext.xml中創建的bean? – ufk

+0

這是一個十幾個或多或少的優雅解決方案的問題。結帳:[1](http://stackoverflow.com/questions/1296052),[2](http://stackoverflow.com/questions/4031293),[3](http://stackoverflow.com/questions/ 2072101)和[4](https://jira.springsource.org/browse/SPR-4049) –