2015-09-12 2 views
0

I весна проект использование Hessian web сервис (пользовательMgr). В моем клиенте (UserProfileHelperImpl) настройка пружины работает с автоустановкой автозапуска, но не с аннотацией @Autowire. Как я могу получить то же самое с @Autowire? Благодарю.Как получить аннотацию @Autowire с веб-сервисом Hessian? (Setter autowire произведение хорошо)

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>web</display-name> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> 
    </listener> 
</web-app> 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:task="http://www.springframework.org/schema/task" 
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd 
    http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"  
default-autowire="byName"> 
    <context:annotation-config /> 
    <context:spring-configured /> 
    <task:annotation-driven /> 
    <import resource="applicationContext-service.xml" /> 
    <import resource="applicationContext-business.xml" /> 
</beans> 

ApplicationContext-service.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" 
    default-autowire="byName"> 
    <bean id="userMgr" 
class="org.springframework.remoting.caucho.HessianProxyFactoryBean" scope="prototype"> 
    <property name="hessian2Request" value="true" /> 
    <property name="hessian2Reply" value="true" /> 
    <property name="serviceUrl" value='#{config.getFullUrl("userMgr")}' /> 
    <property name="serviceInterface" value="com.core.business.UserMgr" /> 
    </bean> 
</beans> 

ApplicationContext-business.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" 
    default-autowire="byName"> 
    <bean id="userProfileHelper" class="com.web.business.common.UserProfileHelperImpl" scope="prototype"> 
<!--  <property name="userMgr" ref="userMgr"/> --> 
    </bean> 
</beans> 

UserProfileHelper.java

package com.web.business.common; 

@Component 
public interface UserProfileHelper { 
    Profile getUserProfile(String userName); 
} 

UserProfileHelperImpl.java

package com.web.business.common; 

public class UserProfileHelperImpl implements UserProfileHelper { 
    @Autowired // this does not work 
    private UserMgr userMgr; 

    // this work 
    /*public void setUserMgr(UserMgr userMgr) { 
    this.userMgr = userMgr; 
    }*/ 
} 

UserMgr.java

package com.core.business; 

public interface UserMgr { 

    Profile getUserProfile(String userName); 
} 

ответ

0

Вы не должны писать AttributeMgr вместо UserMgr?

@Autowired 
private AttributeMgr userMgr; 
+0

Кроме того, в '<имя = значение "serviceInterface" свойство = "com.business.UserMgr"/>' не должно это быть 'com.core.business.UserMgr' вместо просто' ком. business.UserMgr'? Я не знаю, как Сеттер работает на вас. – user2004685

+0

Я снова просмотрел все и исправил какое-то место. Поскольку каждый файл длинный, и все такие же, поэтому я удаляю некоторый избыточный код. – drakid

+0

Вы даете 'default-autowire =" byName "' while '@ Autowired' использовать' 'byType" '. '' byName "' всегда вводит зависимость с помощью setter. Если вы хотите использовать аннотацию, не указывайте 'default-autowire =" byName "' или, возможно, используете '@ Qualifier' в дополнение к' @ Autowired'. – user2004685

Смежные вопросы