spring mvc - Don't see webpage at http://localhost:8080/greeting -
i have project structure:
build.gradle
buildscript { ext { springbootversion = '1.4.1.release' } repositories { mavencentral() mavenlocal() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}") } } apply plugin: 'war' apply plugin: 'spring-boot' jar { basename = 'accouting' version = '0.0.1-snapshot' } sourcecompatibility = 1.8 targetcompatibility = 1.8 repositories { mavencentral() mavenlocal() } dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-web') compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile("org.springframework.boot:spring-boot-devtools") compile('com.oracle:ojdbc6:11.2.0.4') providedruntime('org.springframework.boot:spring-boot-starter-tomcat') testcompile('org.springframework.boot:spring-boot-starter-test') }
application.java
package com.example; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.boot.builder.springapplicationbuilder; import org.springframework.boot.web.support.springbootservletinitializer; @springbootapplication public class application extends springbootservletinitializer { @override protected springapplicationbuilder configure(springapplicationbuilder application) { return application.sources(application.class); } public static void main(string[] args) throws exception { springapplication.run(application.class, args); } }
greetingcontroller.java
package hello; import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestparam; @controller public class greetingcontroller { @requestmapping("/greeting") public string greeting(@requestparam(value="name", required=false, defaultvalue="world") string name, model model) { model.addattribute("name", name); return "greeting"; } }
index.html
<!doctype html> <html> <head> <title>getting started: serving web content</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <p>get greeting <a href="/greeting">here</a></p> </body> </html>
application.properties
#basic spring boot config oracle spring.datasource.url=jdbc:oracle:thin:@//192.168.1.42:1521/xe spring.datasource.username=system spring.datasource.password=123456 spring.datasource.driver-class-name=oracle.jdbc.oracledriver datasource.mine.poolsize=30 # hibernate config spring.jpa.database-platform=org.hibernate.dialect.oracle10gdialect spring.mvc.view.prefix=/ spring.mvc.view.suffix=.jsp
greeting.html
<!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>getting started: serving web content</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <p th:text="'hello, ' + ${name} + '!'" /> </body> </html>
i don't see webpage @ http://localhost:8080/greeting
, how fix it?
your greetingcontroller in package. move com.example
, should solve problem.
if still want keep package structure, use @componentscan(basepackages = "hello")
, have:
package com.example; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.boot.builder.springapplicationbuilder; import org.springframework.boot.web.support.springbootservletinitializer; import org.springframework.context.annotation.componentscan; @springbootapplication @componentscan(basepackages = "hello") public class application extends springbootservletinitializer { @override protected springapplicationbuilder configure(springapplicationbuilder application) { return application.sources(application.class); } public static void main(string[] args) throws exception { springapplication.run(application.class, args); } }
Comments
Post a Comment