当Spring Boot中的方法非静态时,@ Autowire返回null

时间:2017-04-25 17:52:59

标签: spring intellij-idea spring-boot

我在Spring Boot中遇到了一些自动装配问题。其中一些问题与IntelliJ https://youtrack.jetbrains.com/issue/IDEA-139669有关。但我现在注意到了一些事情。

在一个课程中,我试图像这样自动装配UserDetailsService

@Autowired
UserDetailsService userDetailsService;

public void someMethod() {
userDetailsService.getUserDetails();
}

如果getUserDetials方法static UserDetailsService如下@Service public class UserDetailsService { public static void getUserDetails() { System.out.println("Output from UserDetailsService"); } 。然后自动装配工作。

getUserDetials

但如果static方法不是UserDetailsService中的java.lang.NullPointerException: null,则如下所示。然后,当我尝试使用自动装配时,userDetailsService.getUserDetails()会收到以下错误@Service public class UserDetailsService { public void getUserDetails() { System.out.println("Output from UserDetailsService"); }

static

自动装配是否依赖于方法2017-04-24 15:35:13,429 DEBUG [AIF]: CommData.updateWorkflow - END 2017-04-24 15:35:13,429 DEBUG [AIF]: AIFUtil.callOdiServlet - START 2017-04-24 15:35:13,451 INFO [AIF]: EssbaseService.loadData - START 2017-04-24 15:35:13,507 DEBUG [AIF]: appId:3, appType:ESSBASE, mcFlag:false, dataLoadMethod:CLASSIC_VIA_EPMI, mDataFlowNode:LOCAL, textDataLoad:N, isFccsLoad:false, isJournalLoad:false 2017-04-24 15:35:13,508 DEBUG [AIF]: LOAD_METHOD:ESSFILE, LOAD_TYPE:DATA, EXPORT_MODE:STORE_DATA, CREATE_DRILL_REGION:false, PURGE_DATA_FILE:true, BATCH_SIZE:10000 2017-04-24 15:35:13,629 INFO [AIF]: cloudServiceType: Planning, Resolved user name for application access: epm_default_cloud_admin 2017-04-24 15:35:14,816 DEBUG [AIF]: Obtained connection to essbase cube: Finance 2017-04-24 15:35:14,818 DEBUG [AIF]: Resolved essbase rule file name for loading: AIF0069 2017-04-24 15:35:14,819 DEBUG [AIF]: Fetching rule file from essbase server for data loading: AIF0069 2017-04-24 15:35:14,824 INFO [AIF]: Starting executeDataRuleFile... 2017-04-24 15:35:14,826 DEBUG [AIF]: Locked rule file: AIF0069 2017-04-24 15:35:14,827 INFO [AIF]: Getting load buffer for ASO data load... 2017-04-24 15:35:14,828 INFO [AIF]: Initializing load buffer [1] 2017-04-24 15:35:14,828 INFO [AIF]: Successfully initialized the load buffer 2017-04-24 15:35:14,828 INFO [AIF]: Loading data into cube using data file... 2017-04-24 15:35:14,844 INFO [AIF]: purge data file: /u03/inbox/outbox/AQCONSOL_930.dat 2017-04-24 15:35:14,845 INFO [AIF]: The load buffer [1] has been closed. 2017-04-24 15:35:14,845 INFO [AIF]: **Load data encountered** the following errors: | Error: 3303 | A99999 | "A99999","01","Functional","L000","Default Version","C10010","P0000","J00000","FY16","G00","Actual","[YearTotal].[Q1].[Jan]",100 | 2017-04-24 15:35:14,845 INFO [AIF]: Load data failed. 2017-04-24 15:35:14,846 DEBUG [AIF]: Unlocked rule file: AIF0069 2017-04-24 15:35:14,846 ERROR [AIF]: Load data failed. 2017-04-24 15:35:14,853 INFO [AIF]: EssbaseService.loadData - END (false) 2017-04-24 15:35:14,871 DEBUG [AIF]: AIFUtil.callOdiServlet - END 2017-04-24 15:35:14,871 FATAL [AIF]: Error in CommData.loadData Traceback (most recent call last): File "<string>", line 4769, in loadData RuntimeError: false 或者它只是IntelliJ的问题,或者我在这里遗漏了其他东西?

0 个答案:

没有答案