Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-06-27 11:27:51,561 -
***************************
APPLICATION FAILED TO START
***************************
Description:
Field noticeDao in com.am.service.impl.NoticeServiceImpl required a bean of type 'com.am.dao.NoticeDao' that could not be found.
Action:
Consider defining a bean of type 'com.am.dao.NoticeDao' in your configuration.
Process finished with exit code 1
可是dao层加了@Repository注解了
![图片说明](https://img-ask.csdn.net/upload/201806/27/1530070235_440891.png)
control层
package com.am.controller;
import com.am.entity.Notice;
import com.am.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.*;
@RequestMapping("/notice")
@RestController
public class NoticeController {
@Autowired
private NoticeService noticeService;
@RequestMapping("login")
@ResponseBody
public Map<String, String> login() {
Map<String, String> hashMap = new HashMap<>();
hashMap.put("msg", "登录成功");
return hashMap;
}
@RequestMapping(value="/list",method = RequestMethod.GET)
@ResponseBody
public List<Notice> getAll(){
List<Notice> list = noticeService.findAll();
return list;
}
/*
@RequestMapping(value="/list",method = RequestMethod.GET)
@ResponseBody
public String getAll(ModelMap map){
map.addAttribute("list",noticeService.findAll());
return "inform_list";
}
*/
@GetMapping("/add")
@ResponseBody
public Notice save(@Valid Notice notice){
notice.setNoauthor(notice.getNoauthor());
notice.setNoticeid(notice.getNoticeid());
notice.setNotime(new Date());
notice.setNotitle(notice.getNotitle());
notice.setOperation(notice.getOperation());
Notice no = noticeService.save(notice);
return no;
}
service层
package com.am.service;
import com.am.entity.Notice;
import java.util.*;
public interface NoticeService {
/**查询所有公告*/
List<Notice> findAll();
/**添加公告*/
Notice save(Notice notice);
/**删除公告列表*/
void delete(Notice notice);
/**根据公告id删除*/
void deleteById(Integer noticeId);
/**修改公告信息*/
void updateById(Notice notice);
Notice findById(Integer noticeid);
}
service实现类
package com.am.service.impl;
import com.am.dao.NoticeDao;
import com.am.entity.Notice;
import com.am.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
private NoticeDao noticeDao;
@Override
public List<Notice> findAll() {
return noticeDao.findAll();
}
@Override
public Notice save(Notice notice) {
return noticeDao.save(notice);
}
@Override
public void delete(Notice notice) {
noticeDao.delete(notice);
}
@Override
public void deleteById(Integer noticeId) {
noticeDao.deleteById(noticeId);
}
@Override
public void updateById(Notice notice) {
noticeDao.save(notice);
}
@Override
public Notice findById(Integer noticeid) {
return noticeDao.findById(noticeid).get();
}
}
实体层
package com.am.entity;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.*;
@Data
@DynamicUpdate
@Table(name="t_notice")
@Entity
public class Notice {
@Id
private Integer noticeid;
/*公告标题*/
private String notitle;
/*公告内容*/
private String text;
/*公告图片*/
private String picture;
/*发布者id*/
private Integer userid;
/*发布者*/
private String noauthor;
/*发布时间*/
private Date notime;
/*操作*/
private String operation;
}
pom文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.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>
<!--
<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>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
配置文件
server:
servlet:
context-path: /
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&userSSL=false
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
thymeleaf:
encoding: utf-8
cache: false
mode: HTML5
2018-06-27 11:27:51,561 -
***************************
APPLICATION FAILED TO START
***************************
Description:
Field noticeDao in com.am.service.impl.NoticeServiceImpl required a bean of type 'com.am.dao.NoticeDao' that could not be found.
Action:
Consider defining a bean of type 'com.am.dao.NoticeDao' in your configuration.
Process finished with exit code 1
可是dao层加了@Repository注解了
![图片说明](https://img-ask.csdn.net/upload/201806/27/1530070235_440891.png)
control层
package com.am.controller;
import com.am.entity.Notice;
import com.am.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.*;
@RequestMapping("/notice")
@RestController
public class NoticeController {
@Autowired
private NoticeService noticeService;
@RequestMapping("login")
@ResponseBody
public Map<String, String> login() {
Map<String, String> hashMap = new HashMap<>();
hashMap.put("msg", "登录成功");
return hashMap;
}
@RequestMapping(value="/list",method = RequestMethod.GET)
@ResponseBody
public List<Notice> getAll(){
List<Notice> list = noticeService.findAll();
return list;
}
/*
@RequestMapping(value="/list",method = RequestMethod.GET)
@ResponseBody
public String getAll(ModelMap map){
map.addAttribute("list",noticeService.findAll());
return "inform_list";
}
*/
@GetMapping("/add")
@ResponseBody
public Notice save(@Valid Notice notice){
notice.setNoauthor(notice.getNoauthor());
notice.setNoticeid(notice.getNoticeid());
notice.setNotime(new Date());
notice.setNotitle(notice.getNotitle());
notice.setOperation(notice.getOperation());
Notice no = noticeService.save(notice);
return no;
}
service层
package com.am.service;
import com.am.entity.Notice;
import java.util.*;
public interface NoticeService {
/**查询所有公告*/
List<Notice> findAll();
/**添加公告*/
Notice save(Notice notice);
/**删除公告列表*/
void delete(Notice notice);
/**根据公告id删除*/
void deleteById(Integer noticeId);
/**修改公告信息*/
void updateById(Notice notice);
Notice findById(Integer noticeid);
}
service实现类
package com.am.service.impl;
import com.am.dao.NoticeDao;
import com.am.entity.Notice;
import com.am.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
private NoticeDao noticeDao;
@Override
public List<Notice> findAll() {
return noticeDao.findAll();
}
@Override
public Notice save(Notice notice) {
return noticeDao.save(notice);
}
@Override
public void delete(Notice notice) {
noticeDao.delete(notice);
}
@Override
public void deleteById(Integer noticeId) {
noticeDao.deleteById(noticeId);
}
@Override
public void updateById(Notice notice) {
noticeDao.save(notice);
}
@Override
public Notice findById(Integer noticeid) {
return noticeDao.findById(noticeid).get();
}
}
实体层
package com.am.entity;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.*;
@Data
@DynamicUpdate
@Table(name="t_notice")
@Entity
public class Notice {
@Id
private Integer noticeid;
/*公告标题*/
private String notitle;
/*公告内容*/
private String text;
/*公告图片*/
private String picture;
/*发布者id*/
private Integer userid;
/*发布者*/
private String noauthor;
/*发布时间*/
private Date notime;
/*操作*/
private String operation;
}
pom文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.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>
<!--
<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>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
配置文件
server:
servlet:
context-path: /
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&userSSL=false
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
thymeleaf:
encoding: utf-8
cache: false
mode: HTML5