gpt4 book ai didi

java - ContextLoader - 上下文初始化失败

转载 作者:行者123 更新时间:2023-12-02 05:16:30 26 4
gpt4 key购买 nike

无法启动已部署的 war 文件。我在终端收到以下错误

[ERROR] 17:23:17 ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in resource loaded from byte array: Cannot resolve reference to bean 'blPersistenceUnitManager' while setting bean property 'persistenceUnitManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blPersistenceUnitManager': Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blMergedDataSources' defined in resource loaded from byte array: Cannot resolve reference to bean 'webDS' while setting bean property 'sourceMap' with key [TypedStringValue: value [jdbc/web], target type [null]];

最终的以下堆栈跟踪是由出于调试目的引发的错误以及尝试终止导致非法访问的线程而引发的,并且没有功能影响。

Context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<ResourceLink global="jdbc/web" name="jdbc/web" type="javax.sql.DataSource"/>


</Context>

Server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>

<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
initialSize="5"
maxActive="120"
maxIdle="5"
maxWait="5000"
name="jdbc/web"
username="root"
password="admin123"
poolPreparedStatements="true"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/broadleaf"
validationQuery="select 1"/>
</GlobalNamingResources>

<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

</Host>
</Engine>
</Service>
</Server>

感谢您的宝贵建议。我已经用 server.xml 和 context.xml 编辑了这篇文章。

我正在关注 Broadleafcommerce 的教程 [ http://www.broadleafcommerce.com/docs/core/current/getting-started]

为了配置切换到 MySql,我已按照此链接进行了更改 [ http://www.broadleafcommerce.com/docs/core/current/tutorials/getting-started-tutorials/switch-to-mysql-tutorial]

applicationContext-servlet.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">


<context:component-scan base-package="org.broadleafcommerce.common.web"/>
<context:component-scan base-package="org.broadleafcommerce.profile.web.controller"/>
<context:component-scan base-package="org.broadleafcommerce.profile.web.core.service.login"/>


<context:component-scan base-package="com.heatclinic.sample" />

<!-- Turn on AOP annotations (required by Broadleaf) -->
<aop:config/>


<bean class="org.broadleafcommerce.core.web.catalog.ProductHandlerMapping">
<property name="order" value="2"/>
</bean>


<bean class="org.broadleafcommerce.cms.web.PageHandlerMapping">
<property name="order" value="3"/>
</bean>


<bean class="org.broadleafcommerce.core.web.catalog.CategoryHandlerMapping">
<property name="order" value="4"/>
</bean>


<context:component-scan base-package="com.heatclinic.controller" />


<mvc:annotation-driven/>



<mvc:interceptors>
<bean id="webContentInterceptor" class="org.broadleafcommerce.core.web.interceptor.NonResourceWebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
</bean>

<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="blLocaleCode"/>
</bean>
</mvc:interceptors>


<bean id="localeResolver" class="org.broadleafcommerce.common.web.BroadleafCookieLocaleResolver" />


<mvc:resources order="-10" location="/img/, classpath:/common_style/img/" mapping="/img/**" />
<mvc:resources order="-10" location="/fonts/, classpath:/common_style/fonts/" mapping="/fonts/**" />
<mvc:resources order="-10" location="WEB-INF/favicon.ico" mapping="/favicon.ico" />


<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="-10" />
<property name="mappings">
<props>
<prop key="/js/**">blJsResources</prop>
<prop key="/css/**">blCssResources</prop>
</props>
</property>
</bean>

<!-- Set up the view resolver to be used by Spring -->
<bean class="org.broadleafcommerce.common.web.BroadleafThymeleafViewResolver">
<property name="templateEngine" ref="blWebTemplateEngine" />
<property name="order" value="1" />
<property name="cache" value="${thymeleaf.view.resolver.cache}" />
<property name="fullPageLayout" value="layout/fullPageLayout" />
<property name="characterEncoding" value="UTF-8" />
<property name="layoutMap">
<map>
<entry key="account/" value="layout/accountLayout" />
<entry key="catalog/" value="NONE" />
<entry key="checkout/" value="layout/checkoutLayout" />
<entry key="checkout/confirmation" value="layout/fullPageNoNavLayout" />
<entry key="layout/" value="NONE" />
<entry key="content/NONE" value="NONE" />
</map>
</property>
</bean>


<bean id="blShippingInfoFormValidator" class="org.broadleafcommerce.core.web.checkout.validator.USShippingInfoFormValidator" />

</beans>

即使我已将 hibernate-3.2.7.ga.jar 文件添加到 lib 目录中,我还是收到此异常 -ClassLoadingException:Unable to load class [org.hibernate.dialect.MySQL5InnoDBDialect] 。

[ERROR] 11:09:39 ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blEntityManagerFactorySecureInfo' defined in resource loaded from byte array: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: blSecurePU] Unable to build EntityManagerFactory

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: blSecurePU] Unable to build EntityManagerFactory ....

Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQL5InnoDBDialect ...

Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySQL5InnoDBDialect ] ....

Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySQL5InnoDBDialect ...

但是 jar 文件确实有该类。

3576 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MckoiDialect.class
5326 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MimerSQLDialect.class
595 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQL5Dialect.class
648 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQL5InnoDBDialect.class
9682 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLDialect.class
642 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLInnoDBDialect.class
544 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLMyISAMDialect.class

而且我还没有提到 pom.xml 文件中有关 hibernate 依赖项的任何内容。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.heatclinic</groupId>
<artifactId>ecommerce-website</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>ecommerce</name>
<url>http://www.blc-archetype.com</url>
<properties>
<blc.version>3.1.8-GA</blc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>My Company's eCommerce Website</description>
<repositories>
<repository>
<id>public snapshots</id>
<name>public snapshots</name>
<url>http://nexus.broadleafcommerce.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<build>
<pluginManagement>
<plugins>
<plugin>

<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>
[1.7,)
</versionRange>
<goals>
<goal>
timestamp-property
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
keytool-maven-plugin
</artifactId>
<versionRange>
[1.5,)
</versionRange>
<goals>
<goal>clean</goal>
<goal>generateKeyPair</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<version>1.1.3</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>

<fileset>
<directory>target</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<!-- Activated by the profiles above for the paths to tools.jar-->
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>[1.6,)</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>

<dependency>
<groupId>com.heatclinic</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<!--Broadleaf libraries -->
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-common</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-profile</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-profile-web</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-framework</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-framework-web</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-admin-module</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-contentmanagement-module</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-open-admin-platform</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>integration</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<!-- Other dependencies -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.9</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>7.0.30</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>admin</module>
<module>core</module>
<module>site</module>
</modules>
</project>

我在项目中找不到名为 applicationContext-servlet-cms-contentClient.xml 的文件。

最佳答案

我希望你发布了你的 spring 配置的 xml,这样我就可以看看是否还有其他问题,但至少你需要在 tomcat 中定义所有你的 jndi 名称 -在 server.xml 中作为 <resource /><globalnames />和 context.xml 为 <resourcelink /><context />标签。 Server.xml 看起来像这样(您需要为您使用的数据库类型选择正确的设置):

<GlobalNamingResources>
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
initialSize="5"
maxActive="120"
maxIdle="5"
maxWait="5000"
name="jdbc/web"
username="user"
password="password"
poolPreparedStatements="true"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/dbname"
validationQuery="select 1"/>
</GlobalNamingResources>

尽管不要删除已定义的资源。这在 context.xml 中:

<context>    
<ResourceLink global="jdbc/web" name="jdbc/web" type="javax.sql.DataSource"/>
</context>

我不想因为包含链接而被扣款,但如果您搜索“tomcat jndi datasource how to”,我想您至少会找到一个完整的示例来说明所需内容。您还需要在 tomcat/lib 中包含包含驱动程序的 jar(本例中为 com.mysql.jdbc.Driver)。

关于java - ContextLoader - 上下文初始化失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26903186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com