Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Jdbc+;Wildfly不支持@AutoWired服务层_Java_Spring_Wildfly_Spring Jdbc_Wildfly 10 - Fatal编程技术网

Java Spring Jdbc+;Wildfly不支持@AutoWired服务层

Java Spring Jdbc+;Wildfly不支持@AutoWired服务层,java,spring,wildfly,spring-jdbc,wildfly-10,Java,Spring,Wildfly,Spring Jdbc,Wildfly 10,各位晚上好, 在使用SpringJDBCTemplate+wildfly 10进行的一些测试中,我遇到了一些非常奇怪的问题,当我通过soapui调用soap Web服务时,我的服务层没有被注入,这使得eclipse向我显示了一个悲伤而忧郁的NullPointerException 例外情况: Caused by: java.lang.NullPointerException at com.gtac.usuario.webservice.soap.UsuarioWebServiceImpl

各位晚上好, 在使用SpringJDBCTemplate+wildfly 10进行的一些测试中,我遇到了一些非常奇怪的问题,当我通过soapui调用soap Web服务时,我的服务层没有被注入,这使得eclipse向我显示了一个悲伤而忧郁的NullPointerException

例外情况:

Caused by: java.lang.NullPointerException
    at com.gtac.usuario.webservice.soap.UsuarioWebServiceImpl.numero(UsuarioWebServiceImpl.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.webservices.deployers.WSComponentInstanceAssociationInterceptor.processInvocation(WSComponentInstanceAssociationInterceptor.java:56)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
    at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:198)
    at org.jboss.as.webservices.invocation.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:137)
    at org.jboss.wsf.stack.cxf.JBossWSInvoker.performInvocation(JBossWSInvoker.java:169)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
依赖项:

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.3.0.Final</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.0.0</version>
        </dependency>
Dao层实现:

package com.gtac.usuario.dao;

import org.springframework.stereotype.Repository;

import com.gtac.util.dao.JdbcConnection;

@Repository
public class UsuarioDaoImpl extends JdbcConnection implements UsuarioDao{

    @Override
    public int numero() {
        return getJdbcTemplate().queryForObject("select * from teste", Integer.class);
    }



}
Dao的层接口:

package com.gtac.usuario.dao;

public interface UsuarioDao {

    public int numero();

}
实施的服务

package com.gtac.usuario.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gtac.usuario.dao.UsuarioDao;

@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class UsuarioServiceImpl implements UsuarioService {

    @Autowired
    private UsuarioDao usuarioDao;

    @Override
    public int numero() {
        return usuarioDao.numero();
    }

}
服务的层接口

package com.gtac.usuario.service;

public interface UsuarioService {
    public int numero();
}
Web服务层

package com.gtac.usuario.webservice.soap;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gtac.usuario.service.UsuarioService;

@WebService(serviceName = "UsuarioWebService")
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
@Service
public class UsuarioWebServiceImpl {

    @Autowired
    private UsuarioService usuarioService;

    @WebMethod
    public int numero() {
        return this.usuarioService.numero();
    }

    @WebMethod(exclude=true)
    public UsuarioService getUsuarioService() {
        return usuarioService;
    }

    @WebMethod(exclude=true)
    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

}
有一件事我忘了提: 当我第一次启动wildfly 10时,它会接收数据源 它是在JdbcTemplate中设置的


另一件事:正如您在JdbcConnection.java中看到的,我有一行代码在数据源插入jdbccontemplate之后执行select。很好。我解决了这个问题。解决方案在手册中:

我应该简单地在我的Web服务层中扩展SpringBeanAutowiringSupport

package com.gtac.usuario.webservice.soap;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gtac.usuario.service.UsuarioService;

@WebService(serviceName = "UsuarioWebService")
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
@Service
public class UsuarioWebServiceImpl extends SpringBeanAutowiringSupport  {

    @Autowired
    private UsuarioService usuarioService;

    @WebMethod
    public int numero() {
        return this.usuarioService.numero();
    }

    @WebMethod(exclude=true)
    public UsuarioService getUsuarioService() {
        return usuarioService;
    }

    @WebMethod(exclude=true)
    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

}
package com.gtac.usuario.service;

public interface UsuarioService {
    public int numero();
}
package com.gtac.usuario.webservice.soap;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gtac.usuario.service.UsuarioService;

@WebService(serviceName = "UsuarioWebService")
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
@Service
public class UsuarioWebServiceImpl {

    @Autowired
    private UsuarioService usuarioService;

    @WebMethod
    public int numero() {
        return this.usuarioService.numero();
    }

    @WebMethod(exclude=true)
    public UsuarioService getUsuarioService() {
        return usuarioService;
    }

    @WebMethod(exclude=true)
    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

}
package com.gtac.usuario.webservice.soap;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gtac.usuario.service.UsuarioService;

@WebService(serviceName = "UsuarioWebService")
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
@Service
public class UsuarioWebServiceImpl extends SpringBeanAutowiringSupport  {

    @Autowired
    private UsuarioService usuarioService;

    @WebMethod
    public int numero() {
        return this.usuarioService.numero();
    }

    @WebMethod(exclude=true)
    public UsuarioService getUsuarioService() {
        return usuarioService;
    }

    @WebMethod(exclude=true)
    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

}