Springboot2.1.6版本部署resin4.0.62
Resin 简介
Resin是CAUCHO公司的产品,是一个application server,对servlet和JSP提供了良好的支持,性能也比较优良,resin自身采用JAVA语言开发。(by百度百科)
总结一句话就是和Tomcat一样优秀的WEB容器!
SpringBoot部署Resin
- 第一步:jar包该war包
<!--jar改为war-->
<packaging>war</packaging>
- 第二步:Springboot启动类,继承SpringBootServletInitializer
package cn.pconline;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class ApiApplication extends SpringBootServletInitializer{
/**
* 外部容器加载springboot项目配置,继承SpringBootServletInitializer
* http://www.baowenwei.com/post/spring/ji-ci-springboot-bu-shu-dao-resinrong-qi
*
* @param builder
* @return
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApiApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
- 第三步:将war包解压到部署路径下
<!--我将其解压在默认webapps/ROOT下-->
<web-app id="/" root-directory="webapps/ROOT"/>
- 第四步:启动报错
019-07-25 16:35:57.678 ERROR 9896 --- [ resin-41] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1236)
The following method did not exist:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;
The method's class, javax.persistence.Table, is available from the following locations:
jar:file:/D:/resin/resin-4.0.62/lib/javaee-16.jar!/javax/persistence/Table.class
jar:file:/D:/resin/resin-4.0.62/webapps/ROOT/WEB-INF/lib/javax.persistence-api-2.2.jar!/javax/persistence/Table.class
It was loaded from the following location:
file:/D:/resin/resin-4.0.62/lib/javaee-16.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.persistence.Table
[19-07-25 16:35:57.679] {resin-41} WebApp[production/webapp/default/ROOT] fail
[19-07-25 16:35:57.685] {main} java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1236)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:830)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
at com.caucho.server.webapp.WebApp.callInitializer(WebApp.java:3674)
at com.caucho.server.webapp.WebApp.callInitializers(WebApp.java:3539)
at com.caucho.server.webapp.WebApp.startImpl(WebApp.java:3882)
at com.caucho.server.webapp.WebApp.access$700(WebApp.java:209)
at com.caucho.server.webapp.WebApp$StartupTask.run(WebApp.java:5451)
at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
[19-07-25 16:35:58.041] {resin-51} WebApp[production/webapp/default/resin-doc] active
对于这个错误网上说什么的都有,hibernate jpa包冲突、javaee-16.jar包冲突了等等,吐槽这么优秀的一款容器怎么这么垃圾集成一大堆乱七八糟jar干什么。
亲测Springboot2.1.6、resin4.0.62可用的解决方法:
在resin.xml根节点最下面添加
<!--解决javax.persistence-api-2.2.jar冲突-->
<class-loader>
<servlet-hack/>
</class-loader>
具体运行机制请参考官网:
https://www.caucho.com/resin-4.0/admin/advanced-classloaders.xtp
参考文档:
https://blog.csdn.net/zh123456zh789/article/details/71127206