I'm working on a Spring Boot application and I'm trying to inject my UserService class into my TenantIdentifierResolver class because I want to use the createUser() method. However i get a nullpointer exception. For some reason userService is set to null, what am I missing here? @Component public class TenantIdentifierResolver implements CurrentTenantIdentifierResolver {      public static final String DEFAULT_TENANT = &quot;default_schema&quot;;      private UserService userService;      @Override     public String resolveCurrentTenantIdentifier() {         String tenant =  TenantContext.getCurrentTenant();         if(tenant != null){             userService.createUser(tenant);             return tenant;         } else {             return DEFAULT_TENANT;         }     }      @Override     public boolean validateExistingCurrentSessions() {         return true;     } }  I've tried to use @Autowired or make a constructor injection but then I got this error: The dependencies of some of the beans in the application context form a cycle: ┌─────┐ |  entityManagerFactory defined in class path resource [org/example/membership/config/HibernateConfig.class] ↑     ↓ |  tenantIdentifierResolver (field private org.example.membership.service.UserService org.example.membership.multitenancy.TenantIdentifierResolver.userService) ↑     ↓ |  userService defined in file [C:\project\Member\server\target\classes\org\example\membership\service\UserService.class] ↑     ↓ |  userRepository defined in org.example.membership.repository.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration ↑     ↓ |  (inner bean)#18957a3d └─────┘  This is my UserService class @Service public class UserService {      private UserRepository userRepository;     private TenantService tenantService;      public UserService(UserRepository repository, TenantService tenantService) {         this.userRepository = repository;         this.tenantService = tenantService;     }      @Transactional     public User createUser(String tenant) {         Tenant tenant = new Tenant();         tenant.setTenantName(tenant);         tenantService.initDatabase(tenant);         return tenant ;     } }  This is my HibernateConfig class @Configuration public class HibernateConfig {     @Autowired     private JpaProperties jpaProperties;      @Bean     JpaVendorAdapter jpaVendorAdapter() {         return new HibernateJpaVendorAdapter();     }          @Bean         LocalContainerEntityManagerFactoryBean entityManagerFactory(         DataSource dataSource,         MultiTenantConnectionProvider multiTenantConnectionProviderImpl,         CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl     ) {          Map&lt;String, Object&gt; jpaPropertiesMap = new HashMap&lt;&gt;(jpaProperties.getProperties());       jpaPropertiesMap.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);       jpaPropertiesMap.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);              jpaPropertiesMap.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);          LocalContainerEntityManagerFactoryBean em = new  LocalContainerEntityManagerFactoryBean();         em.setDataSource(dataSource);         em.setPackagesToScan(&quot;org.example*&quot;);         em.setJpaVendorAdapter(this.jpaVendorAdapter());         em.setJpaPropertyMap(jpaPropertiesMap);         return em;     } }
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
Why is there an electric field in a wire even though it is a conductor? If you take a perfect conductor, there cannot be a field across it since if there were, the particles would arrange themselves in a way to cancel out the field right?  Yet, why does the same not hold true for a wire. A wire is essentially a long, thin conductor yet electrons do indeed flow so there must be an electric field.  Does this not contradict with what happens in a conductor? Why don't the electrons re-arrange to cancel out the electric field? Finding total after percentage has been used? Tried my best with the title. Ok, earlier while I was on break from work (I have low level math, and want to be more fond of mathematics)  I work retail, and 20% of taxes are taken out, and I am wanting to find out how much I made before 20% is taken out.  So I did some scribbling, and this is without googling so please be gentle. but lets say I make 2000 dollars per paycheck, so to see how much money I get after taxes I do 2000 * .8 which gives me 1600. I can also do 2000 * .2 which gives me 400 and then do 2000 - 400 (imo I don't like this way since I have a extra unnecessary step)  Anyways, I was pondering how to reverse that to have the answer be 2000, and what I did was 1600 * 1.20 (120%) which gave me 1920, and I thought that is odd so I did 1600 * 1.25 and answer was 2000 exact.  My question is why did I have to add extra 5% (25%) to get my answer? I am sure I did something wrong, and I fairly confident the formula I am using is a big no no.  edit; wow thank you all for your detailed answers. I am starting to like mathematics more and more. Changing plurality in parentheses If a set of parentheses lies between a subject and its verb, and the parentheses contain an substitutive subject whose singularity/plurality disagrees with the original subject, whose singularity/plurality should be chosen for the verb?  In other words, in the following example, should "questions" (and its verb "are") be singular, or should they remain plural as shown?     Many (if not every) questions on this StackExchange are answered.   My intuition tells me that the two words in question should remain in plural forms, since the text in parentheses only interrupts the sentence (and the sentence would be grammatically incorrect if everything in parentheses were removed and the words were in singular form).  On the other hand, when read aloud (assuming one reads the text in parentheses), this has an uncomfortable sound to it, and I've seen others write in what would be the above example's singular-form case, so I'm curious to find out which is correct.  And, thinking about it, I suppose the same question would apply when commas are used in place of parentheses. I'm robotic engineer. I'm using OpenSCAD to model robotic components (gears, pulleys, parts, etc). But I need application to model physics and interaction of the components (for i.e. how will robot move if I will rotate current gear).  So, is it possible to import OpenSCAD models into Blender and model interactions in it?  I have models in STL format (for i.e. gears). I need to make reductor from it and see how it moves (if possible - measure rotation speed and torque). How do I disable network manager permanently? I'm using Ubuntu 18.04.1 LTS. I want to disable network manager on an Ubuntu machine, because (1) I don't need it, (2) I prefer having hardcoded configuration, and (3) network manager regularly causes issues by changing the DHCP configuration. I tried to follow :  Stop network manager sudo systemctl stop NetworkManager.service  Disable network manager (permanently) to avoid it restarting after a reboot sudo systemctl disable NetworkManager.service   Despite this, the network manager is back again every time I reboot the machine. How can I make it go away? I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found  and others saying on Windows machine the JVM defaults max heap size as 64MB.  Given this situation, how should I deal with this constraint?  I could increase the max heap size using command line option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some finite max does not ultimately get rid of the issue.  I could rewrite some of my code to persist objects to file system frequently (using database is the same thing) to free up the memory. It could work, but it's probably a lot work too.  If you could point me to details of above ideas or some alternatives like automatic virtual memory, extending heap size dynamically, that will be great. How could a statement be true without proof? Godel`s incompleteness theorem states that there may exist true statements which have no proofs in a formal system of particular axioms. Here I have two questions; 1) How can we say that a statement is true without a proof? 2) What has the self reference to do with this? Godel sentence "G" can say that SUB(a,a, no prove) but could be this just arbitrarily judgement about non-provability of "a" because it may simply has a proof which is not yet revealed or discovered? (A kind soul at  suggested I post here as well, sorry if out of bounds.)  I'm trying to programmatically model a damped harmonic spring for use in mobile UI animations (physics mathematics isn't my background, please pardon any misconceptions).  Having derived the parameters for the general case equation, I can iteratively calculate values until I reach a suitable threshold, though because this is bound to "simple" trigonometric and $e^{x}$ functions on the CPU, the 4000-some-odd steps can cause about 0.25 seconds lag on slow devices while it calculates. I'd like to speed this up using my platform's super-optimized vector and BLAS/LAPACK variants.  The requirement for doing this is precalculating the number of steps necessary to reach my threshold value.    In the underdamped case, where the roots of the characteristic function of the differential equation are non-real, I can use algebraic tricks to get my values:  $$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t) + c_{2}e^{r_{2}}\sin(i_{2}t)$$  (Given $r_{1}$, $i_{1}$, $r_{2}$, and $i_{2}$ are the real and irrational components of my two roots, respectively.)  Knowing that $r_{1} = r_{2}$ and $i_{1} = -i_{2}$, I can simplify to:  $$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t)$$  And get my desired value of $t$ for my threshold $a$:  $$t = \arccos(a / c_{1} / e^{r_{1}}) / i_{1}$$    When the roots are real, the equation looks a lot simpler:  $$x(t) = c_{1}e^{r_{1}} + c_{2}e^{r_{2}}$$  However, I don't have my trig functions floating around to help me solve it (even if I did, the irrational components being 0 would cause problems, of course).  Take the concrete example on pages 3-4 of  (my bible during this process), since they at least solve cleanly:  $$x(t) = 1.5e^{-t} - 0.5e^{-3t}$$  I know how I would solve for $t$ to get my for when $x(t) = a$ on paper, by setting $x=e^{t}$, solving, and back substituting, but I don't have that luxury here.  I can make a few assumptions: the roots and constants are all real. I'm always going to be looking for the smallest, first, positive value of $t$. Obviously, the iterative solution is the simplest for this case, but in the end that would involve more steps and therefore be slower no matter what my other optimizations would be. How, then, would I go about solving for my threshold value algorithmically in this (supposedly) simplified case?  Addendum  The underdamped solution presents an extra requirement. The motion curve will oscillate back and forth a few times across the endpoint. Therefore, "first and lowest" $t$ requirement is not necessarily true. In my current, iterative code, the threshold value is both checked against the distance from the current $x(t)$ to the endpoint, as well as to the distance from the previous $x(t)$ as well to allow for a number of oscillations. This might make a more efficient solution nearly impossible. Calculate line distances inside of polygons using ArcGIS for Desktop? I'm working with two data sets:   NHD polyline stream layer for my entire state HUC Watershed boundary Polygons for the entire state   I am looking for a way to calculate the total length of streams within each watershed boundary polygon, and would ideally like to have each polygon then attributed with the sum of stream miles within its boundary.  Can anyone help me? The question asks us to classify all distributions in $\mathbb{R}^2$, say $u$, such that $$(xy)u(x,y) = (x^2-y^2)u(x,y)= 0.$$ I am genuinely stuck, any help is extremely appreciated. At what age does a toddler stop being a toddler? I have a query to insert a row into a table, which has a field called ID, which is populated using an AUTO_INCREMENT on the column. I need to get this value for the next bit of functionality, but when I run the following, it always returns 0 even though the actual value is not 0:  MySqlCommand comm = connect.CreateCommand(); comm.CommandText = insertInvoice; comm.CommandText += "\'" + invoiceDate.ToString("yyyy:MM:dd hh:mm:ss") + "\', " + bookFee + ", " + adminFee + ", " + totalFee + ", " + customerID +  ")"; int id = Convert.ToInt32(comm.ExecuteScalar());   According to my understanding, this should return the ID column, but it just returns 0 every time. Any ideas?  EDIT:  When I run:  "INSERT INTO INVOICE (INVOICE_DATE, BOOK_FEE, ADMIN_FEE, TOTAL_FEE, CUSTOMER_ID) VALUES ('2009:01:01 10:21:12', 50, 7, 57, 2134);last_insert_id();"   I get:  {"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'last_insert_id()' at line 1"} AMT stock option scenario Adding multiple jars to classpath on commandline I'm planning on selling a USB external hard drive that currently contains an old Ubuntu installation with stored passwords and banking information.  How can I securely erase the drive before selling it? Prove by induction that for all $n \ge 0$:  $${n \choose 0} + {n \choose 1} + ... + {n \choose n} = 2^n.$$  In the inductive step, use Pascal’s identity, which is:  $${n+1 \choose k} = {n \choose k-1} + {n \choose k}.$$  I can only prove it using the binomial theorem, not induction. mathtools: \dddot cause the term to rise PCA on correlation or covariance? Removing las2dem streaks from raster DEM? I've created a series of DEM files using the  tool from LAStools; however since I don't have a licensed version they have black streaks running across them. Does anyone know a good method for removing these streaks? Localizing Dynamic Plural Noun messages (e.g. "5 Items Processed") on iPhone using Objective-C