springboot shrio 集成webService

添加依赖

<dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
   <version>3.1.11</version>
</dependency>

写service

@WebService
public interface UserService{
  @WebMethod
   User getUser(User user)
}

写实现类

@WebService(targetNamespace="http://service.demo.paybay.cn/",endpointInterface = "com.sinopec.itnt.modules.webservice.UserService")
@Service("webUserService")
public class UserServiceImpl implements UserService {   @Override
public User getUser(User user) {
   //具体的逻辑
    return userMap.get(user.getUserId());
}
}

发布该接口

@Configuration
public class TestConfig {
    @Autowired
    private Bus bus;

    @Autowired
    private UserService webUserService;

    @Bean
    public Endpoint endpoint() { 
        EndpointImpl endpoint = new EndpointImpl(bus, webUserService);
        endpoint.publish("/UserService");
        return endpoint;
    }
}

用这种方式发布不会出问题?还有一种会出问题,但是不知道问题出在哪

@Bean
//    public ServletRegistrationBean dispatcherServlet() {
//        return new ServletRegistrationBean(new CXFServlet(), "/test/*");
//    }
//    @Bean(name = Bus.DEFAULT_BUS_ID)
//    public SpringBus springBus() {
//        return new SpringBus();
//    }
//    @Bean
//    public UserService userService() {
//        return new UserServiceImpl();
//    }
//    @Bean
//    public Endpoint endpoint() {
//        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
//        endpoint.publish("/user");
//        return endpoint;
//    }

最后启动就可以访问了

如果需要直接访问的话在shiroConfig中过滤器中加入(filterMap.put("/services/**", "anon");)

猜你喜欢

转载自blog.csdn.net/lifei_212/article/details/83027189