我有一个带有Spring Boot的Java应用程序,用MySQL数据库和Spring Security性构建。该应用程序的目的是连接到SOAP API,并使用Thymleaf的前端与数据交互。
当使用IntelliJ IDEA在本地主机上运行该项目时,该项目工作正常,并且具有所有SOAP连接。当运行<code>mvn clean包</code>时,fat jar成功构建。我想将jar文件部署到托管服务器。
感谢任何帮助。
但是当使用<code>java-jar运行它时
错误
2021-10-02 12:47:58.149 WARN 32908 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o
rg.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authController' defined in URL [jar:file:/C:/Users/amerm/Downloads/Compressed/project_name/target/project_name-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/project_name/PersonDetailsClient/Controller/AuthController.class]: Unsatisfied dependency expressed through constr
uctor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personDetailsServiceImpl' defined in URL [jar:fi
le:/C:/Users/amerm/Downloads/Compressed/project_name/target/project_name-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/project_name/PersonDetailsClient/Service/ServiceImpl/PersonDetai
lsServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'personDetailsClient' defined in class path resource [com/project_name/PersonDetailsClient/Config/PersonDetailsClientConfiguration.class]: Bean instantiation via fact
ory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.project.name.PersonDetailsClient.PersonDetailsClient]: Fa
ctory method 'personDetailsClient' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.Sa
ajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
身份验证控制器
@Controller
@RequestMapping(value = "/")
public class AuthController {
@Autowired
public AuthController(UserService userService, RoleDao roleDao, IPersonDetailsService personDetailsService) {
this.personDetailsService = personDetailsService;
this.userService = userService;
this.roleDao = roleDao;
}
private IPersonDetailsService personDetailsService;
private UserService userService;
private RoleDao roleDao;
@RequestMapping
public String home(){
return "redirect:/index";
}
@RequestMapping("index")
public String index(){
return "index";
}
@RequestMapping(value = "signup", method = RequestMethod.GET)
public String signup(Model model) {
PersonDetails personDetails = new PersonDetails();
model.addAttribute("user", personDetails);
return "signup";
}
@RequestMapping(value = "signup", method = RequestMethod.POST)
public String signupPost(@ModelAttribute("user") PersonDetails newPersonDetails, Model model) throws DatatypeConfigurationException {
if (userService.checkUserExists(newPersonDetails.getUsername(), newPersonDetails.getEmailAddress())) {
if (userService.checkEmailExists(newPersonDetails.getEmailAddress())) {
model.addAttribute("emailExists", true);
}
if (userService.checkUsernameExists(newPersonDetails.getUsername())) {
model.addAttribute("usernameExists", true);
}
return "signup";
} else {
Set<UserRole> userRoles = new HashSet<>();
userRoles.add(new UserRole(newPersonDetails, roleDao.findByName("ROLE_USER")));
String personId = personDetailsService.findPersonByVariant1(newPersonDetails.getLastName(), newPersonDetails.getInitials(), newPersonDetails.getDateOfBirth()).getPersonDetails().getPersonId();
userService.createUser(newPersonDetails, userRoles);
PersonDetails user = userService.findByUsername(newPersonDetails.getUsername());
user.setPersonId(personId);
userService.saveUser(user);
if (personId == null){
String personIdCreated = personDetailsService.createPersonByVariant1(newPersonDetails.getLastName(), newPersonDetails.getInitials(), newPersonDetails.getDateOfBirth()).getPersonDetails().getPersonId();
userService.createUser(newPersonDetails, userRoles);
PersonDetails person = userService.findByUsername(newPersonDetails.getUsername());
person.setPersonId(personIdCreated);
userService.saveUser(newPersonDetails);
}
return "redirect:/";
}
}
}
人员详情服务I mpl
@Service
public class PersonDetailsServiceImpl implements IPersonDetailsService {
final String PersonDetailsEndPoint = "ENDPOINT_URL";
final String userId = "NUM";
final String organisationToken = "NUM";
PersonDetailsClient personDetailsClient;
@Autowired
public PersonDetailsServiceImpl(PersonDetailsClient personDetailsClient) {
this.personDetailsClient = personDetailsClient;
}
@Override
public GetPersonDetailsResponse findPersonByVariant1(String lastName, String initials, Date dateOfBirth) throws DatatypeConfigurationException {
ObjectFactory objectFactory = new ObjectFactory();
GetPersonDetailsRequest.PersonDetails person = objectFactory.createGetPersonDetailsRequestPersonDetails();
person.setLastName(lastName);
person.setInitials(initials);
GregorianCalendar bgc = new GregorianCalendar();
bgc.setTime(dateOfBirth);
XMLGregorianCalendar bDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(bgc);
person.setDateOfBirth(bDate);
GetPersonDetailsRequest getPersonDetailsRequest = objectFactory.createGetPersonDetailsRequest();
getPersonDetailsRequest.setPersonDetails(person);
GetPersonDetailsResponse getPersonDetailsResponse = personDetailsClient.getPersonDetailsResponse(PersonDetailsEndPoint, getPersonDetailsRequest, new TokenHeaderRequestCallback(userId, organisationToken));
return getPersonDetailsResponse;
}
@Override
public CreatePersonDetailsResponse createPersonByVariant1(String lastName, String initials, Date dateOfBirth) throws DatatypeConfigurationException {
try {
ObjectFactory objectFactory = new ObjectFactory();
CreatePersonDetailsRequest.PersonDetails person = objectFactory.createCreatePersonDetailsRequestPersonDetails();
person.setLastName(lastName);
person.setInitials(initials);
GregorianCalendar bgc = new GregorianCalendar();
bgc.setTime(dateOfBirth);
XMLGregorianCalendar bDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(bgc);
person.setDateOfBirth(bDate);
CreatePersonDetailsRequest createPersonDetailsRequest = objectFactory.createCreatePersonDetailsRequest();
createPersonDetailsRequest.setPersonDetails(person);
CreatePersonDetailsResponse createPersonDetailsResponse = personDetailsClient.createPersonDetailsResponse(PersonDetailsEndPoint, createPersonDetailsRequest, new TokenHeaderRequestCallback(userId, organisationToken));
return createPersonDetailsResponse;
} catch (SoapFaultClientException soapFaultClientException) {
return null;
}
}
@Override
public CheckChangesPersonDetailsResponse checkPersonChanges(String personId, String title, String lastName, String initials, String firstName, String infix, Date dateOfBirth, String streetName, String houseNumber, String houseNumberAddition, String postalCode, String residence, String country, String countryOfBirth, String lastNameOfBirth, String infixOfBirth, String nationality, GenderType gender, String insurancePolicy, String policyNumber, String socialSecurityNumber, Date dateOfDeath, String telephone, String emailAddress) throws DatatypeConfigurationException {
...
}
@Override
public UpdatePersonDetailsResponse updatePersonDetails(String personId, String title, String lastName, String initials, String firstName, String infix, Date dateOfBirth, String streetName, String houseNumber, String houseNumberAddition, String postalCode, String residence, String country, String countryOfBirth, String lastNameOfBirth, String infixOfBirth, String nationality, GenderType gender, String insurancePolicy, String policyNumber, String socialSecurityNumber, Date dateOfDeath, String telephone, String emailAddress) throws DatatypeConfigurationException {
...
}
}
人员详细信息客户端配置
@Configuration
public class PersonDetailsClientConfiguration {
@Bean
public Jaxb2Marshaller marshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.<project_name>.stub");
marshaller.afterPropertiesSet();
return marshaller;
}
@Bean
public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setDefaultUri("ENDPOINT_URL");
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
return webServiceTemplate;
}
@Bean
public PersonDetailsClient personDetailsClient(Jaxb2Marshaller marshaller) {
PersonDetailsClient personDetailsClient = new PersonDetailsClient();
personDetailsClient.setDefaultUri("ENDPOINT_URL");
personDetailsClient.setMarshaller(marshaller);
personDetailsClient.setUnmarshaller(marshaller);
return personDetailsClient;
}
}
人物详细信息客户端
public class PersonDetailsClient extends WebServiceGatewaySupport {
public GetPersonDetailsResponse getPersonDetailsResponse(String personDetailsEndPoint, GetPersonDetailsRequest getPersonDetailsRequest, TokenHeaderRequestCallback tokenHeaderRequestCallback) {
GetPersonDetailsResponse getPersonDetailsResponse = (GetPersonDetailsResponse) getWebServiceTemplate().marshalSendAndReceive(personDetailsEndPoint, getPersonDetailsRequest, tokenHeaderRequestCallback);
return getPersonDetailsResponse;
}
public CreatePersonDetailsResponse createPersonDetailsResponse (String personDetailsEndPoint, CreatePersonDetailsRequest createPersonDetailsRequest, TokenHeaderRequestCallback tokenHeaderRequestCallback) {
CreatePersonDetailsResponse createPersonDetailsResponse = (CreatePersonDetailsResponse) getWebServiceTemplate().marshalSendAndReceive(personDetailsEndPoint, createPersonDetailsRequest, tokenHeaderRequestCallback);
return createPersonDetailsResponse;
}
public CheckChangesPersonDetailsResponse checkChangesPersonDetailsResponse (String personDetailsEndPoint, CheckChangesPersonDetailsRequest checkChangesPersonDetailsRequest, TokenHeaderRequestCallback tokenHeaderRequestCallback) {
CheckChangesPersonDetailsResponse checkChangesPersonDetailsResponse = (CheckChangesPersonDetailsResponse) getWebServiceTemplate().marshalSendAndReceive(personDetailsEndPoint, checkChangesPersonDetailsRequest, tokenHeaderRequestCallback);
return checkChangesPersonDetailsResponse;
}
public UpdatePersonDetailsResponse updatePersonDetailsResponse (String personDetailsEndPoint, UpdatePersonDetailsRequest updatePersonDetailsRequest, TokenHeaderRequestCallback tokenHeaderRequestCallback) {
UpdatePersonDetailsResponse updatePersonDetailsResponse = (UpdatePersonDetailsResponse) getWebServiceTemplate().marshalSendAndReceive(personDetailsEndPoint, updatePersonDetailsRequest, tokenHeaderRequestCallback);
return updatePersonDetailsResponse;
}
}
绒球.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.<group_name></groupId>
<artifactId><artifactId></artifactId>
<version>0.0.1-SNAPSHOT</version>
<name><Project_name></name>
<properties>
<java.version>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-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>snapshot</id>
<name>Carewebport Snapshots</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.<project_name>.stub</generatePackage>
<schemas>
<schema>
<url>URL.WSDL</url>
</schema>
</schemas>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这可能是由您在运行时使用的 Java 版本引起的。您必须将 javax ws 包添加为依赖项,因为它不再与较新的 Java 版本捆绑在一起。请参阅 Java 11 软件包 javax.xml.soap 不存在以获取更多信息
1.在sts/eclipse中键入ctrl t并键入类名。如果找到了,那么记下它来自的jar名称,比如说x。如果在类路径上没有找到,那么你必须在这个类存在的地方添加依赖项
2 使用任何zip提取器打开在目标文件夹下构建的jar,并在WEB-INF / lib文件夹中检查jar x是否在该x jar下找到javax/xml/soap/SOAPException。