氪金,手把手的Spring Boot Web项目教程,用Spring Boot 建立电商项目,超凡蜘蛛侠游戏

频道:欧洲联赛 日期: 浏览:156

前几节呢,咱们现已简略介绍了SpringBoot结构的运用,从这一节开端,咱们尝试着运用SpringBoot结构来一步一步树立一个简略电商项目。当然了,这不是真实的电商项目,你能够看成是一个CRUD事例,仅仅使用到了SpringBoot结构罢了。

开发工具:eclipse

数据库:MySQL

1.新建项目

你能够看到挑选的pom文件是报错的,让咱们翻开pom文件一探终究。

说是缺失了web.xml文件,那么咱们手动去增加一下。

在这里新建一个WEB-INF文件夹:

再新建一个web.xml文件:

噢耶,pom文件不报错啦!

web.xml



java520.top

index.html
index.htm
index.jsp
default.html
default.htm
default.jsp


在pom文件中增加上SpringBoot的父依靠:


org.springframewo李秉修微博rk.boot
spring-boot-starter-parent
1.5.10.RELEASE


保存,能够看到Maven在主动下载jar包和pom文件了。

再增加上编码和jdk的装备:


UTF-8
UTF-8
1.7

还有jar包依靠:



org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starte兰定远站r-test
test



org.springframework.boot
spring-boot-starter-data-jpa



mysql
mysql-connector-jacandy小滴滴va




插件依靠:

 


org.springframework.boot
spring-boot-maven-plugin



在java源文件夹中创立一个发动类:

代码:

import org.springframework.bcz673oot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

运转,发现报错:

rg.springframework.beans.fact绿角马ory.BeanDefinitionStoreException: Failed to parse configuration class [App]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/social/config/annotation/SocialConfigurerAdapter.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-4.3.氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏14.RELEASE.jar:4.3.14.RELEASE]
at org.springfr氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏amework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272) ~[spring-context-4.3.14.RELEASE.jar:4.3.14菇娘图片.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframew氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏ork吴绪仁.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5那克吾热.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.jav老友趣薯片a:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at App.main(App.java:8) [classes/:na]
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/social/config/annotation/SocialConfigurerAdapter.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.type.class氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏reading.SimpleMetadataReader.(SimpleMetadataReader.java:50) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.type.classreading.Simplb裤eMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:102) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:89) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.t泰安东平气候ype.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataRea氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏derFactory.java:76) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(Co岔开nfigurationClassParser.java:693) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:857) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.contepaperyy论文检测xt.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:328) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~占国桥[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:190) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-cont氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏ext-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-4.3.14.R屋受ELEASE.jar:4.3.14.RELEASE]
... 13 common frames omitted

百度了一下,大约意思好像是不能在默许的包里边发动,得有一个详细的package。

ok,那咱们就给他一个package。

再配上装备文件:

server:
port: 80
context-path: /

运转后报错:

***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

大约的意思呢,就是说springboot主动帮咱们注入DataSource了,而咱们花开堪折txt全集下载在yml文件里边还并没有装备数据库的衔接信息,所以就报错了。

现在,咱们完善一下yml文件:

server:
por腹轮机t: 80
c氪金,手把手的Spring Boot Web项目教程,用Spring Boot 树立电商项目,超凡蜘蛛侠游戏ontext-path: /

spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/db_shop
username: root
password: 123456
jpa:
hibernate:
ddl-auto: update
show-sql: true

数据库选用我本地的MySQL

再次发动,总算不报错了。

现在,新建一个控制器:

测验代码:

package com.java520.top.shop.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
毛线球简笔画
@RequestMapping("/getUserById")
public String getUserById(){
重案追凶by百炼成猫return "Hell Spring Web";
}
}

发动项目,拜访:http://localhost/getUserById

至此,咱们的项目树立结束。