开发者

configure BasicDataSource as bean in web.xml

I'm trying to configure org.apache.commons.dbcp.BasicDataSource as bean in web.xml under a tomcat project using tomcat 6. (it's red5 with tomcat, we can ignore that the main server is actually red5 because i actually run jsp files under port 5080 and don't connect to the red5 directly using RTMP protocol)

my 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>

my 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

does tomcat automatically searches for WEB-INF/web.xml for configuration?

why don't I get any relevant errors to the creation of idDataSource ?

I really don't have any clue how to pinpoint or debug the problem. any assistance would be greatly appreciated.

thank you!

kfir


I don't know nothing about Red5, but it seems like you trying to put Spring beans directly inside web.xml, which is wrong. You are suppose to create a separate Spring configuration file that will be picked up by Springs' ContextLoaderListener. First, add this to your web.xml:

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

Than create applicationContext.xml file under /WEB-INF:

<?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>

Of course all the <bean/> declarations should go away from web.xml.

Second thought: looking at this document it seems like Red5 uses a file named red5-web.xml, please go through this documentation carefully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜