how to add persistence xml files in spring boot - java
I am trying to add spring boot to an existing project that i have. Earlier i had an application context xml file and 4 persistence files along with 3 separate properties files. I used #ImportResource feature of spring to import all the files at once in my application class below #SpringApplication annotation. The code looks like:
#SpringBootApplication
#ComponentScan({"service","web"})
#ImportResource( { "classpath:applicationContext.xml", "classpath:archive-ticket-persistence.xml", "classpath:rest.properties", "classpath:complete-ticket-persistence.xml", "classpath:datasource.properties", "classpath:ticket-persistence.xml", "classpath:user-persistence.xml" } )
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I keep getting this error message every single time i run the application
2015-08-14 12:46:53.658 INFO 6012 --- [ main] Application : Starting Application on squraishi with PID 6012 (C:\Development\newworkspace\Em7Demo\target\classes started by Administrator in C:\Development\newworkspace\Em7Demo)
2015-08-14 12:46:53.721 INFO 6012 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6056677a: startup date [Fri Aug 14 12:46:53 EDT 2015]; root of context hierarchy
2015-08-14 12:46:55.125 INFO 6012 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [applicationContext.xml]
2015-08-14 12:46:55.313 INFO 6012 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [archive-ticket-persistence.xml]
2015-08-14 12:46:56.046 WARN 6012 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://java.sun.com/xml/ns/persistence]
Offending resource: class path resource [archive-ticket-persistence.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1424)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:180)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:144)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:100)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:510)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromImportedResources(ConfigurationClassBeanDefinitionReader.java:347)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:150)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at Application.main(Application.java:12)
2015-08-14 12:46:56.046 INFO 6012 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Development/newworkspace/Em7Demo/target/classes/, file:/C:/Users/Administrator/.m2/repository/com/hostedsolutions/portal/common/1.0-SNAPSHOT/common-1.0-SNAPSHOT.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-data-rest/1.2.5.RELEASE/spring-boot-starter-data-rest-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter/1.2.5.RELEASE/spring-boot-starter-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot/1.2.5.RELEASE/spring-boot-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.2.5.RELEASE/spring-boot-autoconfigure-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.2.5.RELEASE/spring-boot-starter-logging-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/slf4j/jul-to-slf4j/1.7.12/jul-to-slf4j-1.7.12.jar, file:/C:/Users/Administrator/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.12/log4j-over-slf4j-1.7.12.jar, file:/C:/Users/Administrator/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar, file:/C:/Users/Administrator/.m2/repository/ch/qos/logback/logback-core/1.1.3/logback-core-1.1.3.jar, file:/C:/Users/Administrator/.m2/repository/org/yaml/snakeyaml/1.14/snakeyaml-1.14.jar, file:/C:/Users/Administrator/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.4.6/jackson-annotations-2.4.6.jar, file:/C:/Users/Administrator/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.6/jackson-databind-2.4.6.jar, file:/C:/Users/Administrator/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.4.6/jackson-core-2.4.6.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-core/4.1.7.RELEASE/spring-core-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-tx/4.1.7.RELEASE/spring-tx-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/data/spring-data-rest-webmvc/2.2.3.RELEASE/spring-data-rest-webmvc-2.2.3.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/data/spring-data-rest-core/2.2.3.RELEASE/spring-data-rest-core-2.2.3.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/hateoas/spring-hateoas/0.16.0.RELEASE/spring-hateoas-0.16.0.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/plugin/spring-plugin-core/1.1.0.RELEASE/spring-plugin-core-1.1.0.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/atteo/evo-inflector/1.2/evo-inflector-1.2.jar, file:/C:/Users/Administrator/.m2/repository/com/github/fge/json-patch/1.7/json-patch-1.7.jar, file:/C:/Users/Administrator/.m2/repository/com/github/fge/jackson-coreutils/1.6/jackson-coreutils-1.6.jar, file:/C:/Users/Administrator/.m2/repository/com/github/fge/msg-simple/1.1/msg-simple-1.1.jar, file:/C:/Users/Administrator/.m2/repository/com/github/fge/btf/1.2/btf-1.2.jar, file:/C:/Users/Administrator/.m2/repository/com/google/guava/guava/16.0.1/guava-16.0.1.jar, file:/C:/Users/Administrator/.m2/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar, file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar, file:/C:/Users/Administrator/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.12/jcl-over-slf4j-1.7.12.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.2.5.RELEASE/spring-boot-starter-data-jpa-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.2.5.RELEASE/spring-boot-starter-aop-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/aspectj/aspectjrt/1.8.6/aspectjrt-1.8.6.jar, file:/C:/Users/Administrator/.m2/repository/org/aspectj/aspectjweaver/1.8.6/aspectjweaver-1.8.6.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.2.5.RELEASE/spring-boot-starter-jdbc-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-jdbc/4.1.7.RELEASE/spring-jdbc-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.0.23/tomcat-jdbc-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.23/tomcat-juli-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/org/hibernate/hibernate-entitymanager/4.3.10.Final/hibernate-entitymanager-4.3.10.Final.jar, file:/C:/Users/Administrator/.m2/repository/org/jboss/logging/jboss-logging/3.1.3.GA/jboss-logging-3.1.3.GA.jar, file:/C:/Users/Administrator/.m2/repository/org/jboss/logging/jboss-logging-annotations/1.2.0.Beta1/jboss-logging-annotations-1.2.0.Beta1.jar, file:/C:/Users/Administrator/.m2/repository/org/hibernate/hibernate-core/4.3.10.Final/hibernate-core-4.3.10.Final.jar, file:/C:/Users/Administrator/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar, file:/C:/Users/Administrator/.m2/repository/org/jboss/jandex/1.1.0.Final/jandex-1.1.0.Final.jar, file:/C:/Users/Administrator/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar, file:/C:/Users/Administrator/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar, file:/C:/Users/Administrator/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.5.Final/hibernate-commons-annotations-4.0.5.Final.jar, file:/C:/Users/Administrator/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar, file:/C:/Users/Administrator/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar, file:/C:/Users/Administrator/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-orm/4.1.7.RELEASE/spring-orm-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/data/spring-data-jpa/1.7.3.RELEASE/spring-data-jpa-1.7.3.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/data/spring-data-commons/1.9.3.RELEASE/spring-data-commons-1.9.3.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-aspects/4.1.7.RELEASE/spring-aspects-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-security/1.2.5.RELEASE/spring-boot-starter-security-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-beans/4.1.7.RELEASE/spring-beans-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-context/4.1.7.RELEASE/spring-context-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-expression/4.1.7.RELEASE/spring-expression-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-web/4.1.7.RELEASE/spring-web-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/security/spring-security-config/3.2.7.RELEASE/spring-security-config-3.2.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/security/spring-security-core/3.2.7.RELEASE/spring-security-core-3.2.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/security/spring-security-web/3.2.7.RELEASE/spring-security-web-3.2.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-aop/4.1.7.RELEASE/spring-aop-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.2.5.RELEASE/spring-boot-starter-web-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/hibernate/hibernate-validator/5.1.3.Final/hibernate-validator-5.1.3.Final.jar, file:/C:/Users/Administrator/.m2/repository/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-webmvc/4.1.7.RELEASE/spring-webmvc-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.2.5.RELEASE/spring-boot-starter-tomcat-1.2.5.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.23/tomcat-embed-core-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.23/tomcat-embed-el-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/8.0.23/tomcat-embed-logging-juli-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.23/tomcat-embed-websocket-8.0.23.jar, file:/C:/Users/Administrator/.m2/repository/junit/junit/4.12/junit-4.12.jar, file:/C:/Users/Administrator/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.jar, file:/C:/Users/Administrator/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.jms/3.1.1.RELEASE/org.springframework.jms-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.aop/3.1.1.RELEASE/org.springframework.aop-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.beans/3.1.1.RELEASE/org.springframework.beans-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.asm/3.1.1.RELEASE/org.springframework.asm-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.context/3.1.1.RELEASE/org.springframework.context-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.expression/3.1.1.RELEASE/org.springframework.expression-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.core/3.1.1.RELEASE/org.springframework.core-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.transaction/3.1.1.RELEASE/org.springframework.transaction-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/javax/mail/mail/1.4.1/mail-1.4.1.jar, file:/C:/Users/Administrator/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar, file:/C:/Users/Administrator/.m2/repository/org/jsoup/jsoup/1.3.2/jsoup-1.3.2.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.context.support/3.1.1.RELEASE/org.springframework.context.support-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.orm/3.1.1.RELEASE/org.springframework.orm-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.jdbc/3.1.1.RELEASE/org.springframework.jdbc-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.web.portlet/3.1.1.RELEASE/org.springframework.web.portlet-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.web.servlet/3.1.1.RELEASE/org.springframework.web.servlet-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.web/3.1.1.RELEASE/org.springframework.web-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/javax/servlet/jstl/1.2/jstl-1.2.jar, file:/C:/Users/Administrator/.m2/repository/com/google/gwt/gwt-servlet/2.4.0/gwt-servlet-2.4.0.jar, file:/C:/Users/Administrator/.m2/repository/org/sourceforge/gwt-widget/gwt-sl/1.0/gwt-sl-1.0.jar, file:/C:/Users/Administrator/.m2/repository/net/sourceforge/findbugs/annotations/1.3.2/annotations-1.3.2.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-oxm/4.1.7.RELEASE/spring-oxm-4.1.7.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/commons-lang/commons-lang/2.5/commons-lang-2.5.jar, file:/C:/Users/Administrator/.m2/repository/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar, file:/C:/Users/Administrator/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar, file:/C:/Users/Administrator/.m2/repository/commons-digester/commons-digester/2.1/commons-digester-2.1.jar, file:/C:/Users/Administrator/.m2/repository/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar, file:/C:/Users/Administrator/.m2/repository/commons-beanutils/commons-beanutils-core/1.8.0/commons-beanutils-core-1.8.0.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar, file:/C:/Users/Administrator/.m2/repository/commons-codec/commons-codec/1.6/commons-codec-1.6.jar, file:/C:/Users/Administrator/.m2/repository/ca/juliusdavies/not-yet-commons-ssl/0.3.11/not-yet-commons-ssl-0.3.11.jar, file:/C:/Users/Administrator/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar, file:/C:/Users/Administrator/.m2/repository/org/springframework/org.springframework.test/3.1.1.RELEASE/org.springframework.test-3.1.1.RELEASE.jar, file:/C:/Users/Administrator/.m2/repository/c3p0/c3p0/0.9.1/c3p0-0.9.1.jar, file:/C:/Users/Administrator/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.1/jackson-mapper-asl-1.9.1.jar, file:/C:/Users/Administrator/.m2/repository/org/codehaus/jackson/jackson-core-asl/1.9.1/jackson-core-asl-1.9.1.jar, file:/C:/Users/Administrator/.m2/repository/org/apache/httpcomponents/httpcore/4.1.3/httpcore-4.1.3.jar, file:/C:/Users/Administrator/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, file:/C:/Users/Administrator/.m2/repository/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar, file:/C:/Users/Administrator/.m2/repository/commons-pool/commons-pool/1.6/commons-pool-1.6.jar]
2015-08-14 12:46:56.062 ERROR 6012 --- [ main] o.s.boot.SpringApplication : Application startup failed
so im thinking maybe the files that i added are not getting loaded at all. Am i doing something wrong? Can this be done in a better way? Please guide me as im new to spring boot.
EDIT: Adding pom as well
<?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>org.springframework</groupId>
<artifactId>Em7Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Demo</name>
<description>Demo project using Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="PersistenceName" />
</bean>
<jpa:repositories base-package="your.packages.repositories" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
Related
How to create RESTful Web Service with Spring Boot and Apache Camel?
I'm learning Apache Camel in Spring Boot project and I try to create a Retful Webservice and the service is starting but the problem is that I get 404 when I call the endpoint. #Component #RequiredArgsConstructor public class RestJavaDsl extends RouteBuilder { private final WeatherDataProvider weatherDataProvider; #Override public void configure() throws Exception { from("rest:get:javadsl/weather/{city}?produces=application/json") .outputType(WeatherDto.class) .process(this::getWeatherData); } private void getWeatherData(Exchange exchange) { String city = exchange.getMessage().getHeader("city", String.class); WeatherDto currentWeather = weatherDataProvider.getCurrentWeather(city); Message message = new DefaultMessage(exchange.getContext()); message.setBody(currentWeather); exchange.setMessage(message); } } I created this class to hardcode some data: #Component public class WeatherDataProvider { private static Map<String, WeatherDto> weatherData = new HashMap<>(); public WeatherDataProvider() { WeatherDto dto = WeatherDto.builder().city("London").temp("10").unit("C").receivedTime(new Date().toString()).id(1).build(); weatherData.put("LONDON", dto); } public WeatherDto getCurrentWeather(String city) { return weatherData.get(city.toUpperCase()); } public void setCurrentWeather(WeatherDto dto) { dto.setReceivedTime(new Date().toString()); weatherData.put(dto.getCity().toUpperCase(), dto); } } #Data #NoArgsConstructor #AllArgsConstructor #Builder public class WeatherDto implements Serializable { static int counter = 1; private int id = counter++; private String city; private String temp; private String unit; private String receivedTime; } application.yml camel: component: servlet: mapping: context-path: /services/* 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.dgs</groupId> <artifactId>camel-rest-springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>camel-rest-springboot</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> <camel.version>3.14.0</camel.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-starter</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test</artifactId> <scope>test</scope> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jackson</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jaxb</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-servlet</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-servlet-starter</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-rest-starter</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> The serviceis starting and this is the console log: 2022-01-24 20:01:40.353 INFO 15796 --- [ main] c.d.c.CamelRestSpringbootApplication : Starting CamelRestSpringbootApplication using Java 11.0.5 on pc-PC with PID 15796 (D:\Spring Boot\camel-rest-springboot\target\classes started by pc in D:\Spring Boot\camel-rest-springboot) 2022-01-24 20:01:40.357 INFO 15796 --- [ main] c.d.c.CamelRestSpringbootApplication : No active profile set, falling back to default profiles: default 2022-01-24 20:01:43.583 INFO 15796 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-01-24 20:01:43.604 INFO 15796 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-01-24 20:01:43.604 INFO 15796 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-01-24 20:01:43.820 INFO 15796 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-01-24 20:01:43.821 INFO 15796 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3235 ms 2022-01-24 20:01:45.228 INFO 15796 --- [ main] o.a.c.c.s.CamelHttpTransportServlet : Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=] 2022-01-24 20:01:45.233 INFO 15796 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-01-24 20:01:45.592 INFO 15796 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Message DataType is enabled on CamelContext: camel-1 2022-01-24 20:01:45.607 INFO 15796 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Routes startup (total:1 started:1) 2022-01-24 20:01:45.607 INFO 15796 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Started route1 (rest://get:javadsl/weather/%7Bcity%7D) 2022-01-24 20:01:45.607 INFO 15796 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.14.0 (camel-1) started in 370ms (build:83ms init:269ms start:18ms) 2022-01-24 20:01:45.617 INFO 15796 --- [ main] c.d.c.CamelRestSpringbootApplication : Started CamelRestSpringbootApplication in 6.569 seconds (JVM running for 8.087) But when I try to call the endpoint http://localhost:8080/services/javadsl/weather/london It looks like this endpoint doesn't exist, the rest isn't created. I used debugger and the method getWeatherData() isn't called. And I think this log is not ok: Started route1 (rest://get:javadsl/weather/%7Bcity%7D), it should be something like that: route1 started and consuming from servlet:/javadsl/weather/%7Bcity%7D And the tutorial is from here: https://www.youtube.com/watch?v=spDjbC8mZf0&t=433s Thank you in advance!
You can start by creating example project using official camel-archetype-spring-boot maven archetype. You can generate project based on the archetype using your IDE or from command-line using following maven command. mvn archetype:generate -DarchetypeArtifactId="camel-archetype-spring-boot" -DarchetypeGroupId="org.apache.camel.archetypes" -DarchetypeVersion="3.14.0" Now in the maven project file pom.xml add following block to the dependencies <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-jetty-starter</artifactId> </dependency> Note that version doesn't need to be specified as it is provided by camel-spring-boot-dependencies BOM (bill of materials) in dependencyManagement section. After that you can create new file ConfigureCamelContext.java where we can configure our CamelContext and provide it with RestConfiguration. We can do this by implementing CamelContextConfiguration and #Component annotation. The annotation tells spring-framework that it should create instance of the class and inject it to objects that request it based on its class-type or interface. Camel is configured to automatically ask spring-framework for these RestConfiguration instances which it will proceed to use configure CamelContext. package com.example; import org.apache.camel.CamelContext; import org.apache.camel.spi.RestConfiguration; import org.apache.camel.spring.boot.CamelContextConfiguration; import org.springframework.stereotype.Component; #Component public class ConfigureCamelContext implements CamelContextConfiguration { #Override public void beforeApplicationStart(CamelContext camelContext) { RestConfiguration restConfiguration = new RestConfiguration(); restConfiguration.setApiComponent("jetty"); restConfiguration.setApiHost("localhost"); restConfiguration.setPort(8081); camelContext.setRestConfiguration(restConfiguration); } #Override public void afterApplicationStart(CamelContext camelContext) { } } This should work with RestDSL and rest-component. Edit MySpringBootRouter.java to something like this: package com.example; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.springframework.stereotype.Component; #Component public class MySpringBootRouter extends RouteBuilder { static final String CONTET_TYPE_TEXT = "text/plain"; #Override public void configure() { rest() .get("/hello/") .route() .setHeader(Exchange.CONTENT_TYPE, constant(CONTET_TYPE_TEXT)) .setBody().constant("Hello world") .end() .endRest() .get("/hello/{name}") .route() .setHeader(Exchange.CONTENT_TYPE, constant(CONTET_TYPE_TEXT)) .setBody().simple("Hello ${headers.name}") .end() .endRest(); from("rest:get:test?produces=plain/text") .setBody().constant("Hello from JavaDSL"); } } Comment out the class under src/test/java/<grouId>/ as the example test provided by the archetype is not applicable for for MySpringBootRouter and will interrupt build. To run the project you can use command mvn spring-boot:run Now you should be able to open up localhost:8081/hello, localhost:8081/hello/<Name> or localhost:8081/test get response in plain text.
How to fix 'Attribute "default-dependency-check" must be declared for element type "beans".' error in Spring 5
I tried to upgrade Spring from version 4 to version 5 (spring-boot 1.5.x to 2.x.x) in a REST spring boot application. When parsing a config/bean definition file from one of the libraries an error occurs Attribute "default-dependency-check" must be declared for element type "beans"., but that happens only if mentioned attribute - default-dependency-check - is present in the file. Please note that this config file comes from library that I have no control over, therefore I cannot change the version of spring beans dtd, or simply modify the contents of the file, the processing of the file also happens inside the library and seems to be crucial for the application. This problem did not occur with spring-boot 1.5.x. How can I fix/work around this error? Can I make spring ignore the dtd version used in the file? DemoApplication.java package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.support.ClassPathXmlApplicationContext; #SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); System.out.println("Hello"); new ClassPathXmlApplicationContext(new String[]{"classpath*:config/config.xml"}); System.out.println("World"); } } DemoBean.java package com.example.demo; public class DemoBean { public String name; public void setName(String name) { this.name = name; } } resources/config/config.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans default-dependency-check="simple"> <bean id="demoBean" class="com.example.demo.DemoBean"> <property name="name" value="FooBar"/> </bean> </beans> 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <!-- works fine with Spring 4 --> <!--<version>1.5.19.RELEASE</version>--> <relativePath/> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> output/stack trace 2019-08-27 12:58:24.022 INFO 3512 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.673 seconds (JVM running for 1.448) Hello Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from URL [file:/C:/.../default-dependency-check-error-demo/target/classes/config/config.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 42; Attribute "default-dependency-check" must be declared for element type "beans". at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:636) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:95) at com.example.demo.DemoApplication.main(DemoApplication.java:15) Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 42; Attribute "default-dependency-check" must be declared for element type "beans". at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1253) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1917) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:742) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1289) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3132) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:852) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:434) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) ... 14 more Process finished with exit code 1
Spring boot web app not running on tomcat 9
My web App works fine on Eclipse Photon STS, java 8 and Spring Boot 2.02 with the embeded tomcat using endpoint: http://localhost:8081/DataViewer/tspsPatentSearch But when I compile the code into DataViewer.war file (using mvn package) and run it on Tomcat 9 on Linux with endpoint: http://myserver.com:8081/DataViewer/tspsPatentSearch I get the infamous: Whitelabel Error Page There was an unexpected error (type=Not Found, status=404). /DataViewer/tspsPatentSearch My pom.xml file is: `<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.clarivate</groupId> <artifactId>dataviewer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>dataviewer</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <start-class>com.clarivate.dataviewer.DvMain</start-class> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- DS may need to remove for tomcat installation --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> </dependency> </dependencies> <!-- Required to find ojdbc6, because Oracle don't make it available to maven--> <repositories> <repository> <id>codelds</id> <url>https://code.lds.org/nexus/content/groups/main-repo</url> </repository> </repositories> <build> <finalName>DataViewer</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.clarivate.dataviewer.DvMain</mainClass> </configuration> </plugin> </plugins> </build> <description>TSPS data viewer</description> In application.properties I have: spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp server.servlet.path=/DataViewer My main class is: package com.clarivate.dataviewer; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; 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; #SpringBootApplication public class DvMain extends SpringBootServletInitializer { static Logger logger = LogManager.getRootLogger(); public static void main(String[] args) { logger.debug("DS1A in main()"); SpringApplication.run(DvMain.class, args); logger.info("DS1C finished."); } //#Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(DvMain.class); } } My MainController.java has: #GetMapping("/tspsPatentSearch") public String tspsPatentSearch(Model model) { model.addAttribute("tspsPatent", new TspsPatent()); return "tspsPatentSearch"; } The war file unpacks fine and there are no errors. In catalina.out we have: 2018-10-04 12:09:09.954 INFO 12950 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/tspsPatentSearch],methods=[POST]}" onto public java.lang.String com.clarivate.dataviewer.controller.MainController.tspsPatentSearch(com.clarivate.dataviewer.model.TspsPatent,org.springframework.ui.Model,org.springframework.validation.BindingResult) and no errors. I've tried this ie my package structure is correct and this ie my jsp's are in the correct location (data_viewer\src\main\webapp\WEB-INF\jsp) and i'm now running short of ideas. Any help much appreciated Edit: If I copy tspsPatentSearch.jsp into the war file top directory then tomcat finds it. So it looks like tomcat is ignoring: spring.mvc.view.prefix=/WEB-INF/jsp/ or not finding application.properties at all.
Add this to your application.properties: server.servlet.contextPath=/ I've taken your sample code and, assuming you annotated your MainController simply as #Controller, put a deployment together. I changed a few things around, but I believe this was the bit that did it. I haven't been able to find any references explaining why it might be required by Tomcat, but I intend to keep looking. I'll update you if I find anything. Edit: I noticed some duplicate logging in Spring 2.0.2 related to this issue: https://github.com/spring-projects/spring-boot/issues/13470 The problem appeared fixed in 2.0.4 therefore I upgraded. <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> Additionally, I removed the server.servlet.contextPath=/ entry and tada I still can reach the Hello World jsp I set up. If upgrading is possible for you, maybe you could try that before adding something to application.properties which could be considered duplicated functionality. At least I can promise you a better logging experience. Edit #2: No smoking gun, so far, but these (from 2.0.4) could be related: Provide a consistent way to discover the primary DispatcherServlet's path Dispatcher servlets with a custom servlet name are not found by the mappings endpoint Nothing looked likely on a surface scan of 2.0.3. I'm going to give it a rest for now and give you a chance to try some stuff. Good luck! Edit #3: I'm sorry to continue suggesting you switch environment stuff around, but one difference I noted between what I tested and what you're working with is that you seem to be using Tomcat-9.0.0.M20 where as I was testing with 9.0.12. Whether you want to upgrade or not, a few things to note and/or do: 1) Update your question with what you've got now if it's different than before. Include the server.servlet.contextPath=/ in your application.properties just so anyone else looking can see what you've done. 2) The exclusion you have for spring-boot-starter-tomcat under spring-boot-starter-web doesn't appear to do anything - you can verify by comparing the output from running mvn dependency:tree before and after removal. 3) I'm not sure that your spring-web dependency is needed either, as that's brought in by default under the spring-boot-starter. 4) Now to your output. Spring Boot is coming up (note the banner) and your classes are being found and acted upon. catalina.out.DEBUG also in your DS.log starting ~ 08:35:38.162 2018-10-12 09:30:17.322 DEBUG 55745 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/data/apps/tomcat/apache-tomcat-9.0.0.M20/webapps/DataViewer/WEB-INF/classes/com/clarivate/dataviewer/controller/MainController.class] 2018-10-12 09:30:17.328 DEBUG 55745 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/data/apps/tomcat/apache-tomcat-9.0.0.M20/webapps/DataViewer/WEB-INF/classes/com/clarivate/dataviewer/database/ReadFromDb.class] 2018-10-12 09:30:17.356 DEBUG 55745 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/data/apps/tomcat/apache-tomcat-9.0.0.M20/webapps/DataViewer/WEB-INF/classes/com/clarivate/dataviewer/service/FileFuncs.class] 2018-10-12 09:30:17.357 DEBUG 55745 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/data/apps/tomcat/apache-tomcat-9.0.0.M20/webapps/DataViewer/WEB-INF/classes/com/clarivate/dataviewer/service/StringFuncs.class] ... 2018-10-12 09:30:19.417 INFO 55745 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/tspsPatentSearch],methods=[POST]}" onto public java.lang.String com.clarivate.dataviewer.controller.MainController.tspsPatentSearch(com.clarivate.dataviewer.model.TspsPatent,org.springframework.ui.Model,org.springframework.validation.BindingResult) 2018-10-12 09:30:19.417 INFO 55745 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/tspsPatentSearch],methods=[GET]}" onto public java.lang.String com.clarivate.dataviewer.controller.MainController.tspsPatentSearch(org.springframework.ui.Model) ... 2018-10-12 09:30:19.769 INFO 55745 --- [ main] com.clarivate.dataviewer.DvMain : Started DvMain in 3.125 seconds (JVM running for 5.845) And I do indeed note the mapping to /error that's returned for your request at 09:32:11. I find this strange: 2018-10-12 09:32:11.758 DEBUG 55745 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/DataViewer/DataViewer/error] And it's different in DS.log: 2018-10-12 08:36:56.136 DEBUG 6992 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/DataViewer /error] Specifically /DataViewer/DataViewer/error - have you tried requesting http://localhost:8081/DataViewer/DataViewer/tspsPatentSearch In general this appears as though everything is coming up but there is a misconfiguration somewhere that isn't allowing a request to map to the handler.
To confirm. Tomcat adds the war file name to the end point, so if we create DataViewerX.war and set : server.servlet.path=/DataViewer then the end point when running on an external tomcat is: myServer.com/DataViewerX/DataViewer/tspsPatentSearch but when we run on Eclispe, using the source code, then the end point is: http://localhost:8081/DataViewer/tspsPatentSearch which is a bit annoying but not a major problem. A way round this is to call the war file ROOT.war, then tomcat ignores the war file name and the 2 end points are the same, but I have multiple war files in the webapps dir so this solution isn't acceptable for me. If anyone know's a way to allow the 2 end points to be the same then please say so, but it's not that important.
Spring cloud config cannot load native config file unless the filename is application
Something strange happened to me. I have no idea about how to solve it that the spring cloud config cannot load native or cloud config file unless it's filename is 'application.yml/application.properties'. The below code is my configuration: pom.xml: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>micro-certification-config-center</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ConfigServer: #SpringBootApplication #EnableConfigServer public class ConfigServer { public static void main(String[] args) { SpringApplication.run(ConfigServer.class, args); } } application.yml: server: port: 8000 spring: cloud: config: server: native: search-locations: classpath:/shared profiles: active: native The shared folder structor: resources -- shared -- -- application-dev.yml -- -- sms-dev.yml It looks good and run well with no errors, but when I visit http://127.0.0.1:8000/configCenter/dev/master, it only shows the application property source. The response: { "name": "configCenter", "profiles": [ "dev" ], "label": "master", "version": null, "state": null, "propertySources": [ { "name": "classpath:/shared/application-dev.yml", "source": { "logging.level.org.springframework.security": "INFO", "eureka.instance.prefer-ip-address": true, "eureka.client.serviceUrl.defaultZone": "http://registry:8761/eureka/", "security.oauth2.resource.user-info-uri": "http://auth-service:5000/uaa/users/current", "spring.rabbitmq.host": "rabbitmq" } } ] } The server console: 2017-08-24 22:34:08.055 INFO 30010 --- [nio-8000-exec-4] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a931797: startup date [Thu Aug 24 22:34:08 CST 2017]; root of context hierarchy 2017-08-24 22:34:08.062 INFO 30010 --- [nio-8000-exec-4] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2017-08-24 22:34:08.075 INFO 30010 --- [nio-8000-exec-4] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: classpath:/shared/application-dev.yml 2017-08-24 22:34:08.075 INFO 30010 --- [nio-8000-exec-4] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a931797: startup date [Thu Aug 24 22:34:08 CST 2017]; root of context hierarchy All above shows the 'application.yml' file only worked. Can someone help me? Thanks very much!
The external config can help you that. The detail is here: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html You can change this default application config to the external one by command like in the guide line: If you don’t like application.properties as the configuration file name you can switch to another by specifying a spring.config.name environment property. You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths). $ java -jar myproject.jar --spring.config.name=myproject or $ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties Or in your code you can put it like: new SpringApplicationBuilder(Application.class) .properties("spring.config.name:YOUR_EXTERNAL_CONFIG_FILE") .build() .run(args); } Hope this help.
As #spencergibb said, if I want to load sms-dev.yml, I should rename application.name to sms.
Spring-Boot and MySql unable to connect
I am trying to connect to mysql database, but it's not working. I took a course from udemy and followed all steps, but i am getting always the same error, then I followed the steps from this and this guides, but doesn't work. Things i tried so far: new IDE clean & rebuild project deleting property spring.datasource.driverClassName = com.mysql.jdbc.Driver from application.properties tried to add Mysql Connector manually I've ran out of ideas. Need some assistance Update: Stacktrace 2017-03-12 19:20:53.388 INFO 7808 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 2017-03-12 19:20:53.515 INFO 7808 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4 2017-03-12 19:20:54.046 WARN 7808 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory 2017-03-12 19:20:54.061 INFO 7808 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat 2017-03-12 19:20:54.106 INFO 7808 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-03-12 19:20:54.130 ERROR 7808 --- [ main] o.s.boot.SpringApplication : Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE] Packages in eclipse Application.properties 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.stopCozi</groupId> <artifactId>stopCozi</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>StopCozi</name> <description>Stop Cozi </description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- for HTML --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Dependecy for database --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> User Entity #Entity public class User { private String name; private String surname; private String password; #Id #GeneratedValue (strategy= GenerationType.AUTO) private String userId; private String email; private String phoneNo; private String PIN; private List<Appointment> appointmentList; public String getName() { return name; } public void setName(String name) { this.name = name; } //getter and setter UserDaoRepository #RepositoryRestResource(collectionResourceRel = "user", path = "user") public interface UserDaoRepository extends JpaRepository<User, Long>{ User findByName(#Param("name") String name); User findByEmail(#Param("email") String email); }
Try adding this to your maven project file: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> Your application.properties file is just telling spring what jpa provider to use. You still have to include the jdbc provider implementation files.
You need to define the ORM association for this field : private List<Appointment> appointmentList; For example if a User may have multiple Appointment and an Appointment may be related to zero or one User, you could define the Appointment relationship in this way in the User entity : #Entity public class User{ ... #OneToMany(mappedBy="user") private List<Appointment> appointmentList; } And in the Appointment entity you could define this relationship : #Entity public class Appointment{ ... #ManyToOne private User user; ... } If you encounter other mapping errors, I advise you to understand the Hibernate/JPA basics. Here is the actual documentation of Hibernate (v 5): http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html Here is the documentation part on the relationships definition between entities : http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#associations