Avviare un applicazione in Spring su ItelliJ

di il
11 risposte

Avviare un applicazione in Spring su ItelliJ

Ciao a tutti,
Sto leggendo Beginning Spring Boot 2 ma nel capitolo 1 si presenta un'applicazione Spring (non Spring Boot ma Spring) e non riesco a testare l'applicazione su IntelliJ IDEA 2020.
Si apre il browser a:
http://localhost:8080/springmvcjpa-dem
e compare questo:
HTTP Status 404 – Not Found
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.37
L'IDE mi scrive questo:
C:\JAVA\apache-tomcat-9.0.37\bin\catalina.bat run
[2020-07-12 05:33:41,817] Artifact springmvc-jpa-demo:war: Waiting for server connection to start artifact deployment...
[2020-07-12 05:33:41,818] Artifact springmvc-jpa-demo:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2"
Using CATALINA_HOME:   "C:\JAVA\apache-tomcat-9.0.37"
Using CATALINA_TMPDIR: "C:\JAVA\apache-tomcat-9.0.37\temp"
Using JRE_HOME:        "C:\Java\jdk-14.0.1"
Using CLASSPATH:       "C:\JAVA\apache-tomcat-9.0.37\bin\bootstrap.jar;C:\JAVA\apache-tomcat-9.0.37\bin\tomcat-juli.jar"
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
12-Jul-2020 17:33:42.573 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.37
12-Jul-2020 17:33:42.575 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 30 2020 20:09:49 UTC
12-Jul-2020 17:33:42.575 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.37.0
12-Jul-2020 17:33:42.575 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
12-Jul-2020 17:33:42.575 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Java\jdk-14.0.1
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           14.0.1+7
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2
12-Jul-2020 17:33:42.576 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\JAVA\apache-tomcat-9.0.37
12-Jul-2020 17:33:42.577 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
12-Jul-2020 17:33:42.577 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
12-Jul-2020 17:33:42.577 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
12-Jul-2020 17:33:42.577 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2\conf\logging.properties
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2\jmxremote.password
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2\jmxremote.access
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
12-Jul-2020 17:33:42.578 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
12-Jul-2020 17:33:42.579 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_springmvc-jpa-demo_2
12-Jul-2020 17:33:42.589 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\JAVA\apache-tomcat-9.0.37
12-Jul-2020 17:33:42.589 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\JAVA\apache-tomcat-9.0.37\temp
12-Jul-2020 17:33:42.589 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Java\jdk-14.0.1\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\DELL\AppData\Local\Microsoft\WindowsApps;;.]
12-Jul-2020 17:33:42.872 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
12-Jul-2020 17:33:42.915 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [593] milliseconds
12-Jul-2020 17:33:42.963 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
12-Jul-2020 17:33:42.963 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.37]
12-Jul-2020 17:33:42.973 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
12-Jul-2020 17:33:42.982 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [65] milliseconds
Connected to server
[2020-07-12 05:33:43,473] Artifact springmvc-jpa-demo:war: Artifact is being deployed, please wait...
[2020-07-12 05:33:43,474] Artifact springmvc-jpa-demo:war exploded: Artifact is being deployed, please wait...
12-Jul-2020 17:33:46.060 INFO [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
17:33:46,326  INFO RMI TCP Connection(5)-127.0.0.1 context.ContextLoader:304 - Root WebApplicationContext: initialization started
17:33:46,326  INFO RMI TCP Connection(5)-127.0.0.1 support.AnnotationConfigWebApplicationContext:582 - Refreshing Root WebApplicationContext: startup date [Sun Jul 12 17:33:46 CEST 2020]; root of context hierarchy
17:33:46,451  INFO RMI TCP Connection(5)-127.0.0.1 support.AnnotationConfigWebApplicationContext:207 - Registering annotated classes: [class com.apress.demo.config.AppConfig]
17:33:46,925  INFO RMI TCP Connection(5)-127.0.0.1 annotation.AutowiredAnnotationBeanPostProcessor:155 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
17:33:47,237  INFO RMI TCP Connection(5)-127.0.0.1 jpa.LocalContainerEntityManagerFactoryBean:349 - Building JPA container EntityManagerFactory for persistence unit 'default'
17:33:47,269  INFO RMI TCP Connection(5)-127.0.0.1 util.LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [
	name: default
	...]
17:33:47,394  INFO RMI TCP Connection(5)-127.0.0.1 hibernate.Version:45 - HHH000412: Hibernate Core {5.2.5.Final}
17:33:47,394  INFO RMI TCP Connection(5)-127.0.0.1 cfg.Environment:213 - HHH000206: hibernate.properties not found
17:33:47,437  WARN RMI TCP Connection(5)-127.0.0.1 support.AnnotationConfigWebApplicationContext:550 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.apress.demo.config.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
17:33:47,440 ERROR RMI TCP Connection(5)-127.0.0.1 context.ContextLoader:350 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.apress.demo.config.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4676)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1727)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 60 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
	at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:208)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:163)
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
	at com.apress.demo.config.AppConfig.entityManagerFactory(AppConfig.java:79)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$2d61e4a7.CGLIB$entityManagerFactory$2(<generated>)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$2d61e4a7$$FastClassBySpringCGLIB$$a8b60e8.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$2d61e4a7.entityManagerFactory(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 61 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
	... 80 more
12-Jul-2020 17:33:47.456 SEVERE [RMI TCP Connection(5)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
12-Jul-2020 17:33:47.480 SEVERE [RMI TCP Connection(5)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/springmvcjpa-demo] startup failed due to previous errors
[2020-07-12 05:33:47,495] Artifact springmvc-jpa-demo:war: Error during artifact deployment. See server log for details.
12-Jul-2020 17:33:49.011 INFO [RMI TCP Connection(6)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
17:33:49,183  INFO RMI TCP Connection(6)-127.0.0.1 context.ContextLoader:304 - Root WebApplicationContext: initialization started
17:33:49,198  INFO RMI TCP Connection(6)-127.0.0.1 support.AnnotationConfigWebApplicationContext:582 - Refreshing Root WebApplicationContext: startup date [Sun Jul 12 17:33:49 CEST 2020]; root of context hierarchy
17:33:49,245  INFO RMI TCP Connection(6)-127.0.0.1 support.AnnotationConfigWebApplicationContext:207 - Registering annotated classes: [class com.apress.demo.config.AppConfig]
17:33:49,620  INFO RMI TCP Connection(6)-127.0.0.1 annotation.AutowiredAnnotationBeanPostProcessor:155 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
17:33:49,885  INFO RMI TCP Connection(6)-127.0.0.1 jpa.LocalContainerEntityManagerFactoryBean:349 - Building JPA container EntityManagerFactory for persistence unit 'default'
17:33:49,901  INFO RMI TCP Connection(6)-127.0.0.1 util.LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [
	name: default
	...]
17:33:50,026  INFO RMI TCP Connection(6)-127.0.0.1 hibernate.Version:45 - HHH000412: Hibernate Core {5.2.5.Final}
17:33:50,026  INFO RMI TCP Connection(6)-127.0.0.1 cfg.Environment:213 - HHH000206: hibernate.properties not found
17:33:50,042  WARN RMI TCP Connection(6)-127.0.0.1 support.AnnotationConfigWebApplicationContext:550 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.apress.demo.config.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
17:33:50,042 ERROR RMI TCP Connection(6)-127.0.0.1 context.ContextLoader:350 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.apress.demo.config.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4676)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1727)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 60 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
	at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:208)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:163)
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
	at com.apress.demo.config.AppConfig.entityManagerFactory(AppConfig.java:79)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$83511844.CGLIB$entityManagerFactory$2(<generated>)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$83511844$$FastClassBySpringCGLIB$$57f4a454.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at com.apress.demo.config.AppConfig$$EnhancerBySpringCGLIB$$83511844.entityManagerFactory(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 61 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
	... 80 more
12-Jul-2020 17:33:50.057 SEVERE [RMI TCP Connection(6)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
12-Jul-2020 17:33:50.057 SEVERE [RMI TCP Connection(6)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/springmvc_jpa_demo_war_exploded] startup failed due to previous errors
[2020-07-12 05:33:50,073] Artifact springmvc-jpa-demo:war exploded: Error during artifact deployment. See server log for details.
12-Jul-2020 17:33:52.982 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\JAVA\apache-tomcat-9.0.37\webapps\manager]
12-Jul-2020 17:33:53.029 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\JAVA\apache-tomcat-9.0.37\webapps\manager] has finished in [47] ms
Sto usando JDK 1.14 e Tomcat 9.0.37, potrebbe essere questo il problema?
Devo configurare Spring dmServer oppure Tomcat in Run?
grazie

11 Risposte

  • Re: Avviare un applicazione in Spring su ItelliJ

    L'esempio iniziale nel capitolo 1 di quel libro è stato messo solo per fare vedere cosa vuol dire fare una applicazione con Spring Framework "puro" (non Boot) in modo che poi il lettore faccia il paragone con Spring Boot nei capitoli successivi. Insomma, è solo per mostrare che con Spring Framework ti tocca scrivere 10x mentre con Spring Boot basta 1x.

    Comunque quell'esempio iniziale necessita del database MySQL, è ben evidente a pagina 3 in cui mostra la classe AppConfig dove c'è la configurazione del DataSource.

    Il problema comunque è un altro. Hai osservato bene lo stack-trace?? Forse no .... Al fondo si vede:

    Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException

    Questo è relativo a JAXB, la API di "binding" per XML. JAXB è stato originalmente integrato nel framework standard a partire da JavaSE 6. Problema: nei recenti runtime Oracle, JAXB è stato RIMOSSO. in Java SE 9/10 esiste ancora ma è deprecato e va abilitato esplicitamente. In Java SE 11 l'hanno proprio rimosso materialmente e bisognerebbe inserire a mano nel progetto la dipendenza verso una implementazione di JAXB.

    Morale: quel progetto iniziale sarebbe meglio testarlo con un JDK 8 per evitare grane.
  • Re: Avviare un applicazione in Spring su ItelliJ

    Sto usando H2 come database, non MySQL:
    @PropertySource(value = { "classpath:application.properties" })
    ################### DataSource Configuration ##########################
    
    jdbc.driverClassName=org.h2.Driver
    jdbc.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
    jdbc.username=sa
    jdbc.password=
    
    init-db=true
    init-scripts=data.sql
    
    ################### Hibernate Configuration ##########################
    
    hibernate.dialect=org.hibernate.dialect.H2Dialect
    hibernate.show_sql=true
    hibernate.hbm2ddl.auto=update
    packages-to-scan=com.apress.demo
    Del file application.prod-properties nelle classi di configurazione non ve ne è traccia ma non ho ancora installato MySQL su questo notebook.
    Ok, provo a scaricare JDK 8, ma non so come procedere per testare la WebApp. Quando creo un nuovo progetto su IntelliJ ci sono 10000 opzioni. Devo scegliere Spring? Inoltre nel Run cosa devo mettere? Riesci a mandarmi 2 screen shot?
    Grazie per il tuo supporto Andrea
  • Re: Avviare un applicazione in Spring su ItelliJ

    giannino1995 ha scritto:


    Sto usando H2 come database, non MySQL:
    Ma ti stai riferendo a quell'esempio iniziale con Spring Framework puro?? Con Spring Framework NON c'entrano i file application.XXX-properties, è tutto differente.

    P.S. forse è meglio se inizi con Spring Boot ma senza tirare in ballo database, JPA, ecc..
  • Re: Avviare un applicazione in Spring su ItelliJ

    Funziona, bisognava usare JDK 1.8! Bravo Andrea!
  • Re: Avviare un applicazione in Spring su ItelliJ

    Spring è inguardabile, procedo nella lettura se vedo che è troppo difficile cambio libro.
  • Re: Avviare un applicazione in Spring su ItelliJ

    giannino1995 ha scritto:


    Spring è inguardabile
    In che senso è "inguardabile"?? Dubbi su che cosa?
  • Re: Avviare un applicazione in Spring su ItelliJ

    Troppe configurazioni che su Spring Boot non ci sono.
    Ti faccio due domande:
    1) Per installare MySQL sul mio PC seguo questa guida?
    https://www.sqlshack.com/how-to-install-mysql-database-server-8-0-19-on-windows-10/
    2) Gli esempi successivi a quelli del capitolo 1 si possono usare con le ultime versioni di Tomcat e JDK? Non mi convince molto lavorare su del codice "vecchio" che non è più riutilizzare nel 2020. Sono molto perplesso sull'utilità di questa guida.
  • Re: Avviare un applicazione in Spring su ItelliJ

    giannino1995 ha scritto:


    Troppe configurazioni che su Spring Boot non ci sono.
    Certo ma è perché in Spring Framework è tutto più esplicito e da valutare/configurare. In Spring Boot c'è di base meno da fare inizialmente ma solo perché Spring Boot mette in atto tutta una serie di "convenzioni" e valori "predefiniti".

    giannino1995 ha scritto:


    1) Per installare MySQL sul mio PC seguo questa guida?
    https://www.sqlshack.com/how-to-install-mysql-database-server-8-0-19-on-windows-10/
    Non mi pare che serva davvero una "guida" per installare il MySQL. Scarichi l'installer e lo installi come molti altri sw. Essendo un sw "server", l'installer del MySQL ti chiederà un po' di cose: se è un MySQL "Standalone" o altro (non ricordo ora le opzioni), la configurazione TCP/IP (porta, ecc...), la password per "root", se creare un Windows Service e se avviarlo allo startup oppure no, ecc...
    Scegli ovviamente quello che ritieni opportuno ...

    giannino1995 ha scritto:


    2) Gli esempi successivi a quelli del capitolo 1 si possono usare con le ultime versioni di Tomcat e JDK? Non mi convince molto lavorare su del codice "vecchio" che non è più riutilizzare nel 2020. Sono molto perplesso sull'utilità di questa guida.
    Il libro, come concetti, è sicuramente ancora molto valido. Se vuoi usare Java 14, serve almeno Spring Boot 2.2.6 (è scritto qui: Spring Boot 2.2.6 available now).
    E' ovvio che il libro non è aggiornato sulla versione di Spring Boot, né poteva "sapere" di Java 14 dato che il libro è del 2017 !

    Il più recente Tomcat, sì sicuramente puoi usarlo (il 9.x ok, non usare il 10 che è tuttora in alpha). Per Java, continua ad usare un JDK 8, NON ti preoccupare di questo.
  • Re: Avviare un applicazione in Spring su ItelliJ

    Per adattare i codici del libro a Spring Boot 2.2.6 dovrei aggiornare il pom.xml oppure anche i codici delle varie classi della webapp?
    Ti faccio questa domanda perché mi piacerebbe riutilizzare questi esempi nei miei progetti futuri.
  • Re: Avviare un applicazione in Spring su ItelliJ

    giannino1995 ha scritto:


    Per adattare i codici del libro a Spring Boot 2.2.6 dovrei aggiornare il pom.xml oppure anche i codici delle varie classi della webapp?
    Ti faccio questa domanda perché mi piacerebbe riutilizzare questi esempi nei miei progetti futuri.
    Sì, generalmente basta solo cambiare il <version> del spring-boot-starter-parent nel pom.xml (o equivalente per altro tool es. Gradle).
    Salvo, attenzione, cose che in versioni recenti hanno cambiato, rimosso ecc... E queste cose si scoprono solo "conoscendo" Spring Boot e leggendo anche le release note delle varie versioni.

    Questi dettagli e finezze su compatibilità in avanti, ecc.. lasciale "per ultime". NON sono queste che contano, se stai ancora studiando Spring Boot.


    P.S. su GitHub ho un mio demo, spring-boot2-web-thymeleaf-sample, l'avevo fatto più di un anno fa e all'epoca usava Spring Boot 2.1.3. Stamattina ho aggiornato il pom cambiando solo in 2.3.1 (l'ultima attuale) e provando con JDK 14. E funziona. (beh usa "poca" roba, ok)
  • Re: Avviare un applicazione in Spring su ItelliJ

    Ok allora procedo grazie
Devi accedere o registrarti per scrivere nel forum
11 risposte