1. 程式人生 > >springboot shrio 整合webService

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");)