我得到这两个错误我不知道为什么我得到这个错误,请帮助解决这两个错误。如果需要任何进一步的信息,请返回。
第一个错误
java.lang.IllegalStateException:无法在组织上执行CommandLineRunner。SpringFramework Boot SpringApplication。callRunner(SpringApplication.java:771)~[spring-boot-2.7.12.jar:2.7.12]在org. SpringFramework Boot SpringApplication。callRunners(SpringApplication.java:752)~[spring-boot-2.7.12.jar:2.7.12]在www.example.com(SpringApplication.java:314)~[spring-boot-2.7.12.jar:2.7.12]在www.example.com(SpringApplication.java:1303)~[spring-boot-2.7.12.jar:2.7.12]在www.example.com(SpringApplication.java:1292)~[spring-boot-2.7.12.jar:2.7.12],网址为www.example.com_area。ArtAreaApplication. main(ArtAreaApplication.java:19)~[classes/:无] org.springframework.boot.SpringApplication.run (SpringApplication.java:314) ~[spring-boot-2.7.12.jar:2.7.12] at org.springframework.boot.SpringApplication.run (SpringApplication.java:1303) ~[spring-boot-2.7.12.jar:2.7.12] at org.springframework.boot.SpringApplication.run (SpringApplication.java:1292) ~[spring-boot-2.7.12.jar:2.7.12] at project.art_area.ArtAreaApplication.main(ArtAreaApplication.java:19) ~[classes/:na]
第二个错误
原因:java. lang. NullPointerException:无法调用“art_area”。服务。登录服务实施addCustomer(art_area.模型LoginDTO)“因为”这个。loginService "在art_area.api.LoginApi.addCustomer1(LoginApi.java:22)~[classes/:com_area. ArtAreaApplication. addCustomer(ArtAreaApplication.java:38)~[classes/:na] at www.example.com_www.example.com(ArtAreaApplication.java:26)~[classes/:在org. SpringFramework Boot SpringApplication。callRunner(SpringApplication.java:768)~[spring-boot-2.7.12.jar:2.7.12].project.art_area.ArtAreaApplication.addCustomer(ArtAreaApplication.java:38) ~[classes/:na] at project.art_area.ArtAreaApplication.run (ArtAreaApplication.java:26) ~[classes/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768) ~[spring-boot-2.7.12.jar:2.7.12] ... 5 common frames omitted
Main Class:
package project.art_area;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
import art_area.api.LoginApi;
import art_area.model.LoginDTO;
@SpringBootApplication
//@EnableAutoConfiguration(exclude = ArtAreaApplication.class)
public class ArtAreaApplication implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(ArtAreaApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
// TODO Auto-generated method stub
addCustomer();
}
public void addCustomer()
{
LoginApi loginApi=new LoginApi();
LoginDTO loginDTO=new LoginDTO();
loginDTO.setFirstname("A");
loginDTO.setLastname("B");
loginDTO.setPhonenumber("1234567890");
loginDTO.setDoctorname("A");
loginDTO.setSex("M");
String s=loginApi.addCustomer1(loginDTO);
System.out.println(s);
}
}
API Class:
package art_area.api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import art_area.model.LoginDTO;
import art_area.service.LoginService;
import art_area.service.LoginServiceImpl;
@RestController
@RequestMapping(value="/login")
public class LoginApi {
@Autowired
private LoginServiceImpl loginService;
@PostMapping(value = "/customer")
public String addCustomer1(LoginDTO loginDTO)
{
if(loginService.addCustomer(loginDTO));
{
return "customer Successfully added";
}
//return "customer already exists";
}
}
Service Class:
package art_area.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import art_area.model.LoginDTO;
import art_area.repository.LoginRepository;
@Service(value = "loginService")
public class LoginServiceImpl implements LoginService{
@Autowired
private LoginRepository loginRepository;
@Override
public boolean addCustomer(LoginDTO loginDTO) {
// TODO Auto-generated method stub
if(loginRepository.addCustomer(loginDTO))
{
return true;
}
return false;
}
}
1条答案
按热度按时间ecfsfe2w1#
在主应用程序类中更改包
到
(Move java类)
需要进行此更改以允许Spring顺利地自动配置托管bean。