java - cant connect mysql databse using spring boot error HTTP Status 404 the requested resource is not available -
below mentioned code not fetching data mysql database using spring boot maven dependency.after hitting url not displaying json data. working gradle , able connect database , gives me json value. have copied code maven project, no error in code. can me out doing mistake? please let me know if easy way same make code better naive in this.
1) running on server
hitting url (http://localhost:8080/checklistmavenwebthree) throws error instead of giving json value.
let know maven dynamic web project
error - displays on browser http status 404 requested resource not available / spring boot
http status 404 - /checklistmavenwebthree/checklist type status report message /checklistmavenwebthree/checklist description requested resource not available. apache tomcat/7.0.81 when hitting url in postman json data (displays mentioned below rather json value database)
<html> <head> <title>apache tomcat/7.0.81 - error report</title> <style> <!--h1 {font-family:tahoma,arial,sans-serif;color:white;background-color:#525d76;font-size:22px;} h2 {font-family:tahoma,arial,sans-serif;color:white;background-color:#525d76;font-size:16px;} h3 {font-family:tahoma,arial,sans-serif;color:white;background-color:#525d76;font-size:14px;} body {font-family:tahoma,arial,sans-serif;color:black;background-color:white;} b {font-family:tahoma,arial,sans-serif;color:white;background-color:#525d76;} p {font-family:tahoma,arial,sans-serif;background:white;color:black;font-size:12px;}a {color : black;}a.name {color : black;}hr {color : #525d76;}--> </style> </head> <body> <h1>http status 404 - /checklistmavenwebthree/</h1> <hr size="1" noshade="noshade"> <p> <b>type</b> status report </p> <p> <b>message</b> <u>/checklistmavenwebthree/</u> </p> <p> <b>description</b> <u>the requested resource not available.</u> </p> <hr size="1" noshade="noshade"> <h3>apache tomcat/7.0.81</h3> </body> </html> i confused url should hit either project name , path value (mentioned in controller class) 8080/checklistmavenwebthree/checklist or 8080/checklistmavenwebthree this?
file structure looks - > structure:file structure of project
@controller
package com.example.controller; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.pathvariable; import org.springframework.web.bind.annotation.requestbody; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.responsebody; import org.springframework.http.mediatype; import com.example.entity.checklist; import com.example.service.checklistservice; @controller public class checklistcontroller { @autowired private checklistservice checklistservice; @requestmapping(value = "/checklist" , method = requestmethod.get) @responsebody public object index() { return checklistservice.findall(); } @requestmapping(value = "/create", method = requestmethod.put, consumes = mediatype.application_json_value) @responsebody public string create(@requestbody checklist checklist) { string usersitename = ""; try { checklistservice.save(checklist); usersitename = string.valueof(checklist.getsite_name()); system.out.println(usersitename); system.out.println(checklist.getwsc_serial_number()); system.out.println(checklist.getsetup_tech()); system.out.println(checklist.getdate()); system.out.println(checklist.getchecklist_01()); system.out.println(checklist.getchecklist_02()); system.out.println(checklist.getchecklist_03()); system.out.println(checklist.getchecklist_04()); system.out.println(checklist.getchecklist_05()); system.out.println(checklist.getchecklist_06()); system.out.println(checklist.getchecklist_07()); system.out.println(checklist.getchecklist_08()); system.out.println(checklist.getchecklist_09()); system.out.println(checklist.getchecklist_10()); system.out.println(checklist.getchecklist_11()); system.out.println(checklist.getchecklist_12()); system.out.println(checklist.getchecklist_13()); system.out.println(checklist.getchecklist_14()); system.out.println(checklist.getnotes()); system.out.println(checklist.getcompleted_by()); system.out.println(checklist.tostring()); system.out.println("----------------------------------------------------"); }catch(exception e) { return e.tostring(); } return usersitename; } } @application main
package com.example.main; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.boot.autoconfigure.domain.entityscan; import org.springframework.context.annotation.componentscan; import org.springframework.data.jpa.repository.config.enablejparepositories; @enableautoconfiguration @componentscan("com.example") @enablejparepositories("com.example.repository") @springbootapplication @entityscan(basepackageclasses = com.example.entity.checklist.class) public class smartrainchecklistapplication { public static void main(string[] args) { springapplication.run(smartrainchecklistapplication.class, args); } } @entity
package com.example.entity; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.table; @entity @table(name = "checklist") public class checklist { public checklist() { } @column(name = "site_name") private string site_name; @id @column(name = "wsc_serial_number") private long wsc_serial_number; public checklist(long wsc_serial_number) { this.wsc_serial_number = wsc_serial_number; } @column(name = "setup_tech") private string setup_tech; @column(name = "date") private string date; @column(name = "checklist_01") private string checklist_01; @column(name = "checklist_02") private string checklist_02; @column(name = "checklist_03") private string checklist_03; @column(name = "checklist_04") private string checklist_04; @column(name = "checklist_05") private string checklist_05; @column(name = "checklist_06") private string checklist_06; @column(name = "checklist_07") private string checklist_07; @column(name = "checklist_08") private string checklist_08; @column(name = "checklist_09") private string checklist_09; @column(name = "checklist_10") private string checklist_10; @column(name = "checklist_11") private string checklist_11; @column(name = "checklist_12") private string checklist_12; @column(name = "checklist_13") private string checklist_13; @column(name = "checklist_14") private string checklist_14; @column(name = "notes") private string notes; @column(name = "completed_by") private string completed_by; // public checklist(string site_name, long wsc_serial_number, string // setup_tech, string date, string checklist_01, // string checklist_02) { // this.site_name = site_name; // this.wsc_serial_number = wsc_serial_number; // this.setup_tech = setup_tech; // this.date = date; // this.checklist_01 = checklist_01; // this.checklist_02 = checklist_02; // } public checklist(string site_name, long wsc_serial_number, string setup_tech, string date, string checklist_01, string checklist_02, string checklist_03, string checklist_04, string checklist_05, string checklist_06, string checklist_07, string checklist_08, string checklist_09, string checklist_10, string checklist_11, string checklist_12, string checklist_13, string checklist_14, string notes, string completed_by) { super(); site_name = site_name; wsc_serial_number = wsc_serial_number; setup_tech = setup_tech; date = date; checklist_01 = checklist_01; checklist_02 = checklist_02; checklist_03 = checklist_03; checklist_04 = checklist_04; checklist_05 = checklist_05; checklist_06 = checklist_06; checklist_07 = checklist_07; checklist_08 = checklist_08; checklist_09 = checklist_09; checklist_10 = checklist_10; checklist_11 = checklist_11; checklist_12 = checklist_12; checklist_13 = checklist_13; checklist_14 = checklist_14; notes = notes; completed_by = completed_by; } public string getsite_name() { return site_name; } public void setsite_name(string site_name) { site_name = site_name; } public long getwsc_serial_number() { return 0 + + wsc_serial_number; } public void setwsc_serial_number(long wsc_serial_number) { this.wsc_serial_number = wsc_serial_number; } public string getsetup_tech() { return setup_tech; } public void setsetup_tech(string setup_tech) { this.setup_tech = setup_tech; } public string getdate() { return date; } public void setdate(string date) { this.date = date; } public string getchecklist_01() { return checklist_01; } public void setchecklist_01(string checklist_01) { this.checklist_01 = checklist_01; } public string getchecklist_02() { return checklist_02; } public void setchecklist_02(string checklist_02) { this.checklist_02 = checklist_02; } public string getchecklist_03() { return checklist_03; } public void setchecklist_03(string checklist_03) { checklist_03 = checklist_03; } public string getchecklist_04() { return checklist_04; } public void setchecklist_04(string checklist_04) { checklist_04 = checklist_04; } public string getchecklist_05() { return checklist_05; } public void setchecklist_05(string checklist_05) { checklist_05 = checklist_05; } public string getchecklist_06() { return checklist_06; } public void setchecklist_06(string checklist_06) { checklist_06 = checklist_06; } public string getchecklist_07() { return checklist_07; } public void setchecklist_07(string checklist_07) { checklist_07 = checklist_07; } public string getchecklist_08() { return checklist_08; } public void setchecklist_08(string checklist_08) { checklist_08 = checklist_08; } public string getchecklist_09() { return checklist_09; } public void setchecklist_09(string checklist_09) { checklist_09 = checklist_09; } public string getchecklist_10() { return checklist_10; } public void setchecklist_10(string checklist_10) { checklist_10 = checklist_10; } public string getchecklist_11() { return checklist_11; } public void setchecklist_11(string checklist_11) { checklist_11 = checklist_11; } public string getchecklist_12() { return checklist_12; } public void setchecklist_12(string checklist_12) { checklist_12 = checklist_12; } public string getchecklist_13() { return checklist_13; } public void setchecklist_13(string checklist_13) { checklist_13 = checklist_13; } public string getchecklist_14() { return checklist_14; } public void setchecklist_14(string checklist_14) { checklist_14 = checklist_14; } public string getnotes() { return notes; } public void setnotes(string notes) { notes = notes; } public string getcompleted_by() { return completed_by; } public void setcompleted_by(string completed_by) { completed_by = completed_by; } } @application.properties
spring.datasource.url=jdbc:mysql://localhost/smartraindb spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.driver # keep connection alive if idle long time (needed in production) spring.datasource.testwhileidle = true spring.datasource.validationquery = select 1 # show or not log each sql query spring.jpa.show-sql = true # hibernate ddl auto (create, create-drop, update) spring.jpa.hibernate.ddl-auto = update # naming strategy spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.improvednamingstrategy # use spring.jpa.properties.* hibernate native properties (the prefix # stripped before adding them entity manager) # sql dialect makes hibernate generate better sql chosen database spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.mysql5dialect #naming convention according me spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.physicalnamingstrategystandardimpl @ pom.xml
<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>checklistmavenwebthree</groupid> <artifactid>checklistmavenwebthree</artifactid> <version>0.0.1-snapshot</version> <packaging>war</packaging> <dependencies> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.1</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> <version>1.4.7.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> <version>1.4.7.release</version> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>6.0.6</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> <version>1.5.6.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-envers --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-envers</artifactid> <version>1.1.6.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-envers --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-envers</artifactid> <version>5.2.10.final</version> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <testsourcedirectory>src/main/test</testsourcedirectory> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> <resource> <directory>src/main/webapp</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupid>org.apache.tomcat.maven</groupid> <artifactid>tomcat7-maven-plugin</artifactid> <version>7</version> </plugin> <plugin> <artifactid>maven-war-plugin</artifactid> <version>3.0.0</version> </plugin> </plugins> </build> </project> 2) when tried differently , running spring boot app throws error
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: spring boot :: (v1.5.6.release) 2017-08-18 12:51:33.066 info 56824 --- [ main] c.e.main.smartrainchecklistapplication : starting smartrainchecklistapplication on h-h-temp pid 56824 (c:\users\keval.shah\documents\workspace-sts-3.9.0.release-new\checklistmavenwebthree\target\classes started keval.shah in c:\users\keval.shah\documents\workspace-sts-3.9.0.release-new\checklistmavenwebthree) 2017-08-18 12:51:33.068 info 56824 --- [ main] c.e.main.smartrainchecklistapplication : no active profile set, falling default profiles: default 2017-08-18 12:51:33.108 info 56824 --- [ main] ationconfigembeddedwebapplicationcontext : refreshing org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@448ff1a8: startup date [fri aug 18 12:51:33 mdt 2017]; root of context hierarchy 2017-08-18 12:51:33.827 info 56824 --- [ main] .s.d.r.c.repositoryconfigurationdelegate : multiple spring data modules found, entering strict repository configuration mode! 2017-08-18 12:51:34.365 warn 56824 --- [ main] ationconfigembeddedwebapplicationcontext : exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.applicationcontextexception: unable start embedded container; nested exception java.lang.nosuchmethoderror: org.apache.tomcat.util.scan.standardjarscanner.setjarscanfilter(lorg/apache/tomcat/jarscanfilter;)v 2017-08-18 12:51:34.373 info 56824 --- [ main] utoconfigurationreportlogginginitializer : error starting applicationcontext. display auto-configuration report re-run application 'debug' enabled. 2017-08-18 12:51:34.380 error 56824 --- [ main] o.s.boot.springapplication : application startup failed org.springframework.context.applicationcontextexception: unable start embedded container; nested exception java.lang.nosuchmethoderror: org.apache.tomcat.util.scan.standardjarscanner.setjarscanfilter(lorg/apache/tomcat/jarscanfilter;)v @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:137) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:537) ~[spring-context-4.3.9.release.jar:4.3.9.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:122) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.springapplication.refresh(springapplication.java:693) [spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.springapplication.refreshcontext(springapplication.java:360) [spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.springapplication.run(springapplication.java:303) [spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.springapplication.run(springapplication.java:1118) [spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.springapplication.run(springapplication.java:1107) [spring-boot-1.5.6.release.jar:1.5.6.release] @ com.example.main.smartrainchecklistapplication.main(smartrainchecklistapplication.java:19) [classes/:na] caused by: java.lang.nosuchmethoderror: org.apache.tomcat.util.scan.standardjarscanner.setjarscanfilter(lorg/apache/tomcat/jarscanfilter;)v @ org.springframework.boot.context.embedded.tomcat.skippatternjarscanner$tomcat8tldskipsetter.setskippattern(skippatternjarscanner.java:106) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.tomcat.skippatternjarscanner.setpatterntotomcat8skipfilter(skippatternjarscanner.java:61) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.tomcat.skippatternjarscanner.<init>(skippatternjarscanner.java:56) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.tomcat.skippatternjarscanner.apply(skippatternjarscanner.java:87) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.tomcat.tomcatembeddedservletcontainerfactory.preparecontext(tomcatembeddedservletcontainerfactory.java:209) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.tomcat.tomcatembeddedservletcontainerfactory.getembeddedservletcontainer(tomcatembeddedservletcontainerfactory.java:178) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.createembeddedservletcontainer(embeddedwebapplicationcontext.java:164) ~[spring-boot-1.5.6.release.jar:1.5.6.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:134) ~[spring-boot-1.5.6.release.jar:1.5.6.release] ... 8 common frames omitted
looks context path checklistmavenwebthree not defined in properties, http://localhost:8080/checklistmavenwebthree/checklist it's going throw 404. add properties file:
server.contextpath=/checklistmavenwebthree
or hit app this,
http://localhost:8080/checklist
hope helps
Comments
Post a Comment