Java 配置为在端口8080上侦听的Tomcat连接器无法启动。端口可能已在使用中,或者连接器可能配置错误
刀类 应用程序.prprties 存储库Java 配置为在端口8080上侦听的Tomcat连接器无法启动。端口可能已在使用中,或者连接器可能配置错误,java,spring-boot,controller,console,Java,Spring Boot,Controller,Console,刀类 应用程序.prprties 存储库 学生报名表 学生报名表 名字 姓 电子邮件 国家 选择国家 性 男性 女性 部分 编辑学生详细信息 名字 姓 性 男性 女性 电子邮件 部分 国家 选择国家 学生名单 IdFirst Name姓氏 六次修改 电子邮件国家 编辑删除 ${student.id} ${student.firstName} ${student.lastName} ${student.sex} ${student.createdAt} ${student.email} ${st
学生报名表
学生报名表
名字
姓
电子邮件
国家
选择国家
性
男性
女性
部分
编辑学生详细信息
名字
姓
性
男性
女性
电子邮件
部分
国家
选择国家
学生名单
IdFirst Name姓氏
六次修改
电子邮件国家
编辑删除
${student.id}
${student.firstName}
${student.lastName}
${student.sex}
${student.createdAt}
${student.email}
${student.section}
${student.country}
尝试在StudentRepository
界面上添加@Repository
注释,@EnableJpaRepositories(“com.Repository”)
在StudentApplication
类上添加@ComponentScan(“com”)
由于
StudentApplication
类和其他类在不同的包中,因此Spring将无法自动连接studentposition
和StudentDAO
,因此问题就出现。SpringBoot将自动扫描作为包子包的包中的存储库@SpringBootApplication注释类位于
因此,在您的情况下,因为它位于
com.application
中,所以您应该将存储库放在它下面。也许com.application.repository
。否则,您需要像其他人建议的那样,在其他包中使用附加注释来启用组件扫描 你叫我做的我都做了,但没有改变。我完全搞砸了。没有构建不成功的尝试,但我没有得到结果。你说的都是对的,但我的问题没有solve@SushovanMallick你能详细说明你没有得到什么结果或者你在日志中看到了什么吗?当然可以。我想在web上部署我的第一个spring boot web应用程序。但我没有成功。我正在用日志发布整个应用程序。我昨天发布了整个应用程序。现在,我张贴的日志,我得到的每一次。
package com.dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bin.Student;
import com.repository.StudentRepository;
@Service
public class StudentDAO {
@Autowired
StudentRepository studentRepository;
/*to save an employee*/
public Student save(Student std) {
return studentRepository.save(std);
}
/* search all employees*/
public List<Student> findAll(){
return studentRepository.findAll();
}
/*get an employee by id*/
public Student findOne(Integer id){
return studentRepository.getOne(id);
}
/*delete an employee*/
public void delete(Student std) {
studentRepository.delete(std);
}
}
package com.controller;
import java.util.ArrayList;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.bin.Student;
import com.dao.StudentDAO;
@Controller
public class StudentController {
@Autowired
private StudentDAO studentDao;
@RequestMapping(value="/enroll",method=RequestMethod.GET)
public String newRegistration(ModelMap model) {
Student student = new Student();
model.addAttribute("student",student);
return "enroll";
}
@RequestMapping(value="/save",method=RequestMethod.POST)
public String saveRegistration(@Valid Student student,BindingResult result,ModelMap model,RedirectAttributes redirectAttributes) {
if(result.hasErrors()) {
return "enroll";
}
studentDao.save(student);
return "redirect:/viewstudents";
}
@RequestMapping(value="/viewstudents")
public ModelAndView getAll() {
List<Student> list=studentDao.findAll();
return new ModelAndView("viewstudents","list",list);
}
@RequestMapping(value="/editstudent/{id}")
public String edit (@PathVariable int id,ModelMap model) {
Student student=studentDao.findOne(id);
model.addAttribute("student",student);
return "editstudent";
}
@RequestMapping(value="/editsave",method=RequestMethod.POST)
public ModelAndView editsave(@ModelAttribute("student") Student p) {
Student student=studentDao.findOne(p.getId());
student.setFirstName(p.getFirstName());
student.setLastName(p.getLastName());
student.setCountry(p.getCountry());
student.setEmail(p.getEmail());
student.setSection(p.getSection());
student.setSex(p.getSex());
studentDao.save(student);
return new ModelAndView("redirect:/viewstudents");
}
@RequestMapping(value="/deletestudent/{id}",method=RequestMethod.GET)
public ModelAndView delete(@PathVariable int id) {
Student student=studentDao.findOne(id);
studentDao.delete(student);
return new ModelAndView("redirect:/viewstudents");
}
@ModelAttribute("sections")
public List<String> intializeSections(){
List<String> sections = new ArrayList<String>();
sections.add("Graduate");
sections.add("Post Graduate");
sections.add("Reasearch");
return sections;
}
/*
* Method used to populate the country list in view. Note that here you can
* call external systems to provide real data.
*/
@ModelAttribute("countries")
public List<String> initializeCountries() {
List<String> countries = new ArrayList<String>();
countries.add("INDIA");
countries.add("USA");
countries.add("CANADA");
countries.add("FRANCE");
countries.add("GERMANY");
countries.add("ITALY");
countries.add("OTHER");
return countries;
}
}
package com.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication
@EnableJpaAuditing
public class StudentApplication {
public static void main(String[] args) {
SpringApplication.run(StudentApplication.class, args);
}
}
spring.mvc.view.prefix : /WEB-INF/views/
spring.mvc.view.suffix: .jsp
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://localhost:3306/studentdb?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = root
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
package com.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.bin.Student;
public interface StudentRepository extends JpaRepository<Student, Integer> {
}