我有一个带有Spring容器的Jax-Ws Metro项目。我无法自动装配SoapHandler内的字段。我尝试了互联网资源的一切,但没有成功。该字段始终为空。字段名称是“ paymentPortalService”。
我的处理程序类:
public class CustomSoapHeaderHandler extends SpringBeanAutowiringSupport implements SOAPHandler<SOAPMessageContext> {
private static final Logger log = Logger.getLogger(CustomSoapHeaderHandler.class);
@Autowire
private PaymentPortalService paymentPortalService;
}
我有一个称为远程服务的代理服务。将此处理程序添加到远程服务调用方法中的handlerchain中:
@Service
public class CustomServiceProxy {
private final Logger log = Logger.getLogger(CustomServiceProxy.class);
private RemoteServicePort pspPort;
public CustomServiceProxy() {
try {
pspPort = new RemoteService_Service(new URL("https://x?wsdl")).getRemoteServicePort();
Binding binding = ((BindingProvider) pspPort).getBinding();
List<Handler> handlers = binding.getHandlerChain();
handlers.add(new CustomSoapHeaderHandler());
binding.setHandlerChain(handlers);
}
}
我试图将@Autowire更改为@Resource和其他一些来自互联网的解决方案,但没有成功。我正在使用没有EE容器的Apache Tomcat 8。
提前致谢!
最佳答案
Add this jar from ivy
<dependency org="org.springframework" name="spring-aop" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-beans" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-context" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-core" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-expression" rev="4.1.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-web" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-webmvc" rev="4.2.1.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-jdbc" rev="4.2.5.RELEASE" transitive="false"/>
<dependency org="org.springframework" name="spring-tx" rev="4.2.5.RELEASE" transitive="false"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.7.4" transitive="false"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-core" rev="2.7.4" transitive="false"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.7.4" transitive="false"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.39" transitive="false"/>
<dependency org="org.apache.commons" name="commons-dbcp2" rev="2.1.1" transitive="false"/>
<dependency org="org.apache.commons" name="commons-pool2" rev="2.4.2" transitive="false"/>
A response object bean looks like
@Component
public class ResponseObjectBean {
@JsonProperty("code")
private int statusCode;
@JsonProperty("msg")
private String statusMsg;
@JsonProperty("data")
private Object data;
//getter and setter
}
A log in controller
@RestController
public class LogInController {
@Autowired
ResponseObjectBean responseData;
@Autowired
LogInService logInService;
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<ResponseObjectBean> userLogIn(@RequestBody UserInfoBean userInfoBean) {
Object data = null;
String msg = null;
int statusCode;
try {
data = logInService.logIn(userInfoBean);
if (data != null) {
msg = "success";
statusCode = 200;
} else {
msg = "fail";
statusCode = 503;
}
} catch (DataAccessException e) {
msg = "fail";
statusCode = 503;
} catch (Exception e) {
msg = "fail";
statusCode = 503;
e.printStackTrace();
}
responseData.setStatusCode(statusCode);
responseData.setStatusMsg(msg);
responseData.setData(data);
return new ResponseEntity<ResponseObjectBean>(responseData, HttpStatus.OK);
}
}
A log in Service class looks like
@Service
@Transactional
public class LogInService {
@Autowired
LogInDao logInDao;
public UserInfoBean logIn(UserInfoBean userInfoBean) throws DataAccessException {
return logInDao.upSertUser(userInfoBean);
}
}
A log in dao class
@Repository
public class LogInDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public UserInfoBean upSertUser(UserInfoBean userInfoBean) throws Exception {
StringBuilder sql = new StringBuilder();
int count;
UserInfoBean infoBean = null;
try {
// your logic for db operation
return infoBean;
}
} catch (Exception e) {
throw new Exception(e);
} finally {
sql = null;
infoBean = null;
run = null;
}
}
}
for use jdbc templete add these line in your spring.xml
<!-- jdbcTemplate uses dataSource -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- dataSource configuration -->
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="your driverClassName" />
<property name="url" value="your url" />
<property name="username" value="db username" />
<property name="password" value="db password" />
</bean>