gpt4 book ai didi

spring - 我如何在我的 liferay portlet 中使用 spring jar 而不是 ROOT\WEB-INF\lib 中的 spring jar?

转载 作者:行者123 更新时间:2023-11-28 22:18:40 25 4
gpt4 key购买 nike

我有一个我创建的 portlet,我正尝试在其中使用 spring jpa 进行数据检索。我使用的是 Spring 版本 3.2.14,我需要的 spring jar 部署在我的 portlet 的 WEB-INF/lib 文件夹中。

在 tomcat 启动时,我不断收到以下异常:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1052)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:921)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
... 39 more

如果我将调试器附加到 Tomcat,我可以看到它正在使用 ROOT/WEB-INF/lib 中的 spring-beans.jar(版本 3.0.7.RELEASE),它在“packageToScan”中有一个已知问题我的 bean 定义中的 LocalContainerEntityManagerFactoryBean:

<bean id="reportingEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>org.preptoolkit.exercise.reporting.model</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
</bean>
</property>
</bean>

我试过将 spring-beans-3.2.14.RELEASE.jar 放在 $tomcat_home/lib/ext 中,liferay 仍然使用 3.0.7 版本。

Liferay 版本:6.2-ce-ga4

那么如何让 Liferay 为我的 portlet 使用 spring-beans-3.2.14.RELEASE.jar 而不是一个 ROOT?

(我已经在这堵墙上撞了 3 天了)

更新

这是完整的堆栈跟踪:

13:26:55,702 ERROR [localhost-startStop-1][ContextLoader:206] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportingEntityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/persistenceContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1363)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at com.liferay.portal.spring.context.PortletContextLoaderListener.contextInitialized(PortletContextLoaderListener.java:85)
at com.liferay.portal.deploy.hot.SpringHotDeployListener.doInvokeDeploy(SpringHotDeployListener.java:85)
at com.liferay.portal.deploy.hot.SpringHotDeployListener.invokeDeploy(SpringHotDeployListener.java:41)
at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:227)
at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:28)
at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:164)
at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:154)
at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:74)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:58)
at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:116)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1052)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:921)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
... 39 more

最佳答案

有一个 SpringHotDeployListener 尝试为每个 portlet 应用程序初始化 Spring(使用 Liferay 的库)。

要为您的 webapp 关闭它,您必须删除属性 hot.deploy.listeners 中的 com.liferay.portal.deploy.hot.SpringHotDeployListener portal-ext.properties.

如果您使用其他利用 Liferay 的 Spring 环境的 portlet 应用程序,您将需要创建一个 Ext Plugin 并在 ext- 中扩展 SpringHotDeployListener实现:

public class MySpringHotDeployListener extends SpringHotDeployListener {
protected void doInvokeDeploy(HotDeployEvent hotDeployEvent) throws Exception {
if (!hotDeployEvent.getServletContext().getServletContextName().equals("MyContextName")) {
super.doInvokeDeploy(hotDeployEvent);
}
}

// Same for doInvokeUndeploy
}

然后在 portal-ext.properties 中使用 MySpringHotDeployListener 代替 SpringHotDeployListener

关于spring - 我如何在我的 liferay portlet 中使用 spring jar 而不是 ROOT\WEB-INF\lib 中的 spring jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336626/

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