微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

创建在ServletContext资源[/WEB-INF/applicationContext.xml]中定义的名称为'CommonsConfigurationFactoryBean'的bean时出错:

如何解决创建在ServletContext资源[/WEB-INF/applicationContext.xml]中定义的名称为'CommonsConfigurationFactoryBean'的bean时出错:

我遇到了我认为已连接到Postgresql-Tomcat连接的错误。我无法找到我误会的那一块:

我的catalina.out:

    23.10.2020 14:45:27.207 [localhost-startStop-1] WARN  o.s.w.c.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0': Cannot resolve reference to bean 'CommonsConfigurationfactorybean' while setting bean property 'properties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CommonsConfigurationfactorybean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'DatabaseConfiguration' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method Failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.classNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
    at org.springframework.beans.factory.support.BeanDeFinitionValueResolver.resolveReference(BeanDeFinitionValueResolver.java:334) ~[spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    ...........
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CommonsConfigurationfactorybean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'DatabaseConfiguration' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method Failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.classNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
    .........
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method Failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.classNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
    

我的应用程序上下文:

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="psqlDataSource" class="org.springframework.jndi.Jndiobjectfactorybean">
        <property name="jndiName" value="java:comp/env/jdbc/freshSiteDS"/>
        <property name="lookupOnStartup" value="true"/>
        <property name="proxyInterface" value="javax.sql.DataSource"/>
    </bean>


    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="psqlDataSource"/>
    </bean>

    <bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate" depends-on="psqlDataSource">
        <property name="dataSource" ref="psqlDataSource"/>
        <property name="initOnMigrate" value="true"/>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="psqlDataSource" />
    </bean>

    <bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="psqlDataSource" />
    </bean>

    <bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper">
        <property name="propertyNamingStrategy" value="#{T(org.codehaus.jackson.map.PropertyNamingStrategy).CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERscoreS}" />
    </bean>

    <context:property-placeholder file-encoding="UTF-8" properties-ref="CommonsConfigurationfactorybean" ignore-resource-not-found="true" ignore-unresolvable="true"/>

    <bean name="CommonsConfigurationfactorybean"
          class="org.springmodules.commons.configuration.CommonsConfigurationfactorybean">
        <constructor-arg ref="DatabaseConfiguration"/>
    </bean>

    <bean name="DatabaseConfiguration"
          class="org.apache.commons.configuration.DatabaseConfiguration" depends-on="flyway">
        <constructor-arg type="javax.sql.DataSource" ref="psqlDataSource"/>
        <constructor-arg index="1" value="st_application_properties"/>
        <constructor-arg index="2" value="property_key"/>
        <constructor-arg index="3" value="property_value"/>
    </bean>

    <import resource="kernel-context.xml"/>
    <import resource="service-context.xml"/>
    <import resource="security-context2.xml"/>
    <import resource="ws-context.xml"/>
    <import resource="settings-context.xml"/>
    <import resource="migration-context.xml"/>
    <import resource="search-context.xml"/>
</beans>

JDBC驱动程序位于/opt/tomcat/lib/postgresql-42.2.18.jar

请给我一些建议

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。