[英]When I put @Autowire annotaion for JAX WS class it gives null pointer exception error in spring boot
I write a JAX-WS service for my web application and when I call to the web service it gives the null pointer exception(Autowire not working)... I us tomcat 8.5.11 as a server...我为我的 web 应用程序编写了一个 JAX-WS 服务,当我调用该 web 服务时,它给出了空指针异常(Autowire 不工作)...我使用 tomcat 8.5.11 作为服务器...
When I remove the @WebService annotaion the autowire works fine.... But when i add it it doesn't work ... What is the error... Is it error becomes with my dependencies...当我删除 @WebService annotaion 时,自动装配工作正常......但是当我添加它时它不起作用......错误是什么......它是我的依赖项的错误......
This is my Dependencies.这是我的依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<!--handle servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--<Email Dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>1.4.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Add mysql dependency-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
<!--jasper-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>3.7.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jvnet.staxex/stax-ex -->
<dependency>
<groupId>org.jvnet.staxex</groupId>
<artifactId>stax-ex</artifactId>
<version>1.7.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.stream.buffer/streambuffer -->
<dependency>
<groupId>com.sun.xml.stream.buffer</groupId>
<artifactId>streambuffer</artifactId>
<version>1.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-libs -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-libs</artifactId>
<version>1.0.6</version>
</dependency>
My Model is annotated with @Entity annotation..I'm not put it here...我的模型用@Entity 注释进行了注释。我没有把它放在这里......
My repository is我的存储库是
package lk.slsi.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import lk.slsi.domain.CustomsPermit;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
@Qualifier("PermitRepository")
public interface PermitRepository extends CrudRepository < CustomsPermit, Long > {
@Query("select a from CustomsPermit a where a.dtIssue = :dtIssue")
List < CustomsPermit > getPermitByDate(@Param("dtIssue") String dtIssue);
}
My WS class is我的 WS 类是
package lk.slsi.repository;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import lk.slsi.domain.CustomsPermit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
/**
*
* @author lankadeva.ghg
*/
@WebService
@Component
public class permitRepoImpl extends SpringBeanAutowiringSupport {
@Autowired
@Qualifier("PermitRepository")
private PermitRepository permitRepository;
public static void marshaling() throws JAXBException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(CustomsPermit.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
} catch (JAXBException ex) {
Logger.getLogger(permitRepoImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List < CustomsPermit > getPermitByDate(String dtIssue) {
try {
System.out.println("autowire is " + permitRepository);
marshaling();
} catch (JAXBException ex) {
Logger.getLogger(permitRepoImpl.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("exception : autowire is " + permitRepository);
return (List < CustomsPermit > ) ex;
}
return permitRepository.getPermitByDate(dtIssue);
}
}
The Autowire doesn't works in here... When I go on debug mode it gives null as a value Autowire 在这里不起作用...当我进入调试模式时,它给出 null 作为值
This is my web.xml这是我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>SLSIonNationalSingleWindow</display-name>
<servlet-mapping>
<servlet-name>permitRepoImplService</servlet-name>
<url-pattern>/permitRepoImplService</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/view/index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:slsi-servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>permitRepoImplService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
This is my applicationconfig.xml这是我的 applicationconfig.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Scan Config -->
<context:component-scan base-package="lk.slsi" />
<!--<mvc:annotation-driven/>-->
<mvc:default-servlet-handler/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!--<bean id = "permitRepository" class="lk.slsi.repository.PermitRepository"
autowire="byName" autowire-candidate="true">
</bean>-->
</beans>
What is the error in my dependency injection....我的依赖注入有什么错误....
Can you try adding this dependency: jaxws-spring library that integrates the two frameworks:你可以尝试添加这个依赖:集成两个框架的jaxws-spring库:
<dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
</dependency>
Refer this link for more: https://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-spring-integration-example/有关更多信息,请参阅此链接: https ://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-spring-integration-example/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.