java - spring-boot application fails to start -
i start develop web application spring-boot, anf, next guide in offical site, manage create 2 files:
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>spring</groupid> <artifactid>app</artifactid> <version>0.0.1-snapshot</version> <packaging>jar</packaging> <name>app</name> <url>http://maven.apache.org</url> <properties> <start-class>com.spring.app.application</start-class> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.8.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> </dependencies> </project>
application.java
@configuration @enableautoconfiguration @componentscan public class application { public static void main(string[] args) { applicationcontext ctx = springapplication.run(application.class, args); system.out.println("let's inspect beans provided spring boot:"); string[] beannames = ctx.getbeandefinitionnames(); arrays.sort(beannames); (string beanname : beannames) { system.out.println(beanname); } } }
but when seek run application java -jar appname
error: cannot find main class: com.spring.app.application. programme exit
, , in terminal: exception in thread "main" java.lang.noclassdeffounderror: com/spring/app/application
.
what doing wrong?
you have 2 things in pom.xml.
first alter start-class application class. sec add together super-cool spring boot maven builder pom.
something this:
<?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.sample</groupid> <artifactid>beanlist</artifactid> <version>1.0-snapshot</version> <properties> <start-class>com.sample.application</start-class> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.8.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project
then utilize "mvn install" create jar. code runs fine.
java spring spring-mvc spring-boot
No comments:
Post a Comment