springmvc springの二つの文脈問題

22967 ワード

もっと読む
スプリング  mvcとspringの二つの文脈、
1,springはmvcのbeanを得ることができなくて、mvcはあのspringのbeanを得ることができて、springが傍受する方式で一番早い初期化なため、sevletは少し遅くて、この時mvcはまだbeanがなくて、
このような再配置が必要です.直接注釈で生成することはできません.(ここではこのタイミングタスクの前にcontroller層に置いて、このcontrollerはbeanとして注入します.(springmvcのこの注釈が取れないbean)、後は直接に普通のspringスキャンのディレクトリに置いて、より純粋です.
 
また、rabbiitMqなどの傍受形式で配置されたbeanはdispatch.xmlのbeanスキャンより先に、後期は更新されませんので、このbeanに他のbeanを注入すると取れなくなります.
 
このようなJavaハードコードで表示されるのはspring文脈から取ってください.
 
タイミングタスクの例:
 
 
 

<bean id="fInterfaceAccountInfo" class = "com.houbank.incoming.web.util.FInterfaceAccountInfo">bean>

<bean id="t1Order"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject">
        <ref bean="fInterfaceAccountInfo" />
    property>
    <property name="targetMethod">
        <value>getT1Ordervalue>  
property>
bean>

<bean id="cronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    <property name="jobDetail" ref="t1Order">property>
    
<property name="cronExpression" value="0 0/5 * * * ?" />

bean>


<bean id="SpringJobSchedulerFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTriggerBean" />
        list>
    property>
bean>
package com.houbank.incoming.web.util;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.houbank.basic.util.page.Pagination;
import com.houbank.basic.util.response.BaseResponse;
import com.houbank.incoming.api.FinancialSalesSMSMqMessageFacade;
import com.houbank.incoming.api.FinancialSalesUserFacade;
import com.houbank.incoming.common.BaseResponseInterface;
import com.houbank.incoming.model.condition.*;
import com.houbank.incoming.model.domain.*;
import com.houbank.incoming.web.redis.RedisTemplateDelegate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: yy  Date: 2018/3/26 Time: 14:26
 */

@Slf4j
public class FInterfaceAccountInfo {

    @Autowired
    private RestTemplate restTemplate1;

    @Autowired(required=false)
    private RedisTemplate redisTemplate;

    @Reference
    private FinancialSalesUserFacade financialSalesUserFacade;

    @Reference
    private FinancialSalesSMSMqMessageFacade financialSalesSMSMqMessageFacade;

    @Value("${accountInfo}")
    private String  accountInfo;
    @Value("${couponInfo}")
    private String couponInfo;
    @Value("${userOrderInfo}")
    private String userOrderInfo;
    @Value("${userRechargeInfo}")
    private String userRechargeInfo;
    @Value("${userInfo}")
    private String userInfo;
    @Value("${userInvest}")
    private String userInvest;
    @Value("${userWithdraw}")
    private String userWithdraw;
    @Value("${userTransFlow}")
    private String userTransFlow;
    @Value("${userPlan}")
    private String userPlan;



    public BaseResponseInterface>  getT1Order() {
        RedisLock lock = new RedisLock(redisTemplate, "T1_quarz_key", 600000, 800000);
        BaseResponseInterface> stren=null;
        try {
            if(lock.lock()) {
        ParameterizedTypeReference>> responseType = new ParameterizedTypeReference>>() {
            @Override
            public Type getType() {
                return super.getType();
            }
        };
        FinancialInterfaceBaseCondition bc = new FinancialInterfaceBaseCondition();
        ResponseEntity>> str=null;

        try {
            /**
             *      
             */
HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
            headers.add("Accuept", MediaType.APPLICATION_JSON.toString());
//            bc = new FinancialInterfaceCouponCondition();
bc.setAppid("10001");
            bc.setSecret("C34E6AD237D511E8B4670ED5F89F718B");
            long ct=System.currentTimeMillis();
            bc.setTs(ct+29*60*1000);
            String tc= AccountInterfaceUtil.isOk(bc);
            bc.setTicket(tc);
            SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            Date date=sDateFormat.parse("2019-11-11 00:00:00");
//            bc.setEndTime(date);
//            Date date1=sDateFormat.parse("2010-11-11 00:00:00");
//            bc.setExpiryTimeFrom(date1);
//            Date date2=sDateFormat.parse("2019-11-11 00:00:00");
//            bc.setExpiryTimeTo(date2);
//            bc.setPageIndex("1");
//            bc.setPageSize("20");
//            Date date3=sDateFormat.parse("2010-11-11 00:00:00");
//            bc.setStartTime(date3);
//            bc.setUserId("2210983");
            /**
             * POST    ,        
             */
String bodyData = new String(Base64Utils.encode(JSON.toJSONString(bc).getBytes("UTF-8")));

            /**
             *   HttpEntity     ,                ---      
             */
HttpEntity httpEntity = new HttpEntity(bc, headers);
//            str = restTemplate1.exchange(
//                    "http://localhost:8080/hb_phonebank_web/FinancialInterfaceAccountInfo/RateQuery/resultAc",
//                    HttpMethod.POST, httpEntity, responseType);
str = restTemplate1.exchange(userPlan,HttpMethod.POST, httpEntity, responseType);
            System.out.println(str);
            stren = str.getBody();
        }catch (Exception e) {
            log.error("  "+e);
        }

            }

        }catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }

        return stren;

    }

}
 
  • spring.zip(6.7 KB)
  • ダウンロード回数:0