In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces springboot can not reference non-static variables from the static context of how to solve the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that after reading this springboot can not reference non-static variables from the static context of how to solve the article will have a harvest, let's take a look.
Static methods can be called without creating an object, and non-static methods can only be called with an instance of the object.
Therefore, it is impossible to reference a non-static method directly in a static method, because the compiler cannot give the answer without knowing which object's non-static method to call, because there are no objects.
Java is afraid of not finding someone.
Solution:
Spring's set injection method, which injects static variables through a non-static setter method, as shown below
@ PropertySource (value = {"classpath:config/application.yml"}, ignoreResourceNotFound = true,encoding= "UTF-8") @ Service public class tank_task {private static String kafka; public static String getProfilesKafka () {return kafka;} @ Value ("${stream.kafka.servers}") public void setProfilesKafka (String kafka) {tank_task.kafka = kafka } public static void tank_test () {System.out.println ("config static kafka:" + tank_task.getProfilesKafka ());}} on "how to solve the problem that springboot cannot reference non-static variables from a static context". Thank you for reading! I believe that everyone has a certain understanding of "springboot can not reference non-static variables from the static context how to solve" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.