gpt4 book ai didi

java - Spring 5.0.7 与树脂服务器上的 Hibernate 5.4.1

转载 作者:太空宇宙 更新时间:2023-11-04 09:47:38 25 4
gpt4 key购买 nike

此示例在具有相同 jar 的 Tomcat9 中工作正常,但在 Resin 4.0.61 Web 服务器中无法工作resin.xml 文件中 Spring MVC 的配置 -

<servlet>
<servlet-name>springportfolio</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springportfolio-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup></servlet>

<servlet-mapping>
<servlet-name>springportfolio</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

springportfolio-servlet.xml配置文件-

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

<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven />

<!-- Add support for component scanning -->
<context:component-scan
base-package="com.example.portfolio" />

<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"
value="/web-inf/views/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- Step 1: Define Database DataSource / connection pool -->
<bean id="myDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass"
value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl"
value="xxxxxx" />
<property name="user" value="xxxx" />
<property name="password" value="xxx" />

<!-- these are connection pool properties for C3P0 -->
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
</bean>

<!-- Step 2: Setup Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan"
value="com.example.portfolio.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle12cDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<!-- Step 3: Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- Step 4: Enable configuration of transactional behavior based on annotations -->
<tx:annotation-driven
transaction-manager="myTransactionManager" />

出现异常 - 错误 |上下文初始化失败

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImp': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/springportfolio-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

最佳答案

Resin 4.0.61 符合 JEE 6.0 规范。 JEE 6.0 包括版本 2.0 中的 JPA。根据错误消息,应用程序需要 2.1 版本的 JPA。将应用程序降级到 JPA 2.0 或将服务器升级到 JPA 2.1,如本 forum 中所述。

关于java - Spring 5.0.7 与树脂服务器上的 Hibernate 5.4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55218865/

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