问:
How to connect two Foreign Key Fields
I have a model called Part that looks like this:

```<code>class Part(model.Model) =
    some attributes...
    uses = models.ForeignKey('self', null = True, blank = True, on_delete = models.SET_NULL, limit_choices_to={'used_in' : None}, related_name = 'part_uses')
    used_in = models.ForeignKey('self', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'device_used_in')
</code>```

One Part can use or/and be used_in another Part, but I need to know which of them it is, to be able to show this in the DetailView. In other words, it's not enough to know that there is some kind of relationship between two Parts, I need to know which  kind  of relationship. (Thus the two different fields).
Now, I want to update uses in one object, when another is set to used_in, e.g.: if a.uses(b) I want to automatically set b.used_in(a).

I did this by setting it manually in the form_valid method of my UpdateView --> for example, if a.uses is changed, look for b and change its used_in.

For example:

```<code>if 'used_in' in form.changed_data:
    if self.object.used_in:
        other_device = Device.objects.filter(pk= self.object.used_in.pk)[0]
        other_device.uses = self.object
        other_device.save()
</code>```

However, this has several disadvantages. First of all, I don't really like having to do this manually and was wondering whether this could not be done some other way, but I didn't find anything on Google. The second problem is that one Part can use several other Parts, but with my method, only the last Part that was used is shown.

My question is: Is it somehow possible to connect the two foreign keys inside the model, or shift to only one foreign key, or do this in some other way that makes sense.

答:
You can try this format :

```<code>class Parts(models.Model):
    title = models.CharField(u'Store_Title', max_length=100)
    def __str__(self):
        return self.title

class Partused(models.Model):

    mainpart = models.ForeignKey('Parts', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'mainpart')
    subpart = models.ForeignKey('Parts', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'subpart')
    def __str__(self):
        return self.mainpart.title + 'uses --> ' + self.subpart.title
</code>```

Search Part :  Parts.objects.get(title = 'Part_to_find')

Search Part Which have subparts :  Partused.objects.filter(mainpart = 'Part_ID')

Search Part Which are subparts to other parts:  Partused.objects.filter(subpart = 'Part_ID')

Title: How to connect two Foreign Key Fields

Body:
I have a model called Part that looks like this:

class Part(model.Model) =
    some attributes...
    uses = models.ForeignKey('self', null = True, blank = True, on_delete = models.SET_NULL, limit_choices_to={'used_in' : None}, related_name = 'part_uses')
    used_in = models.ForeignKey('self', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'device_used_in')

One Part can use or/and be used_in another Part, but I need to know which of them it is, to be able to show this in the DetailView. In other words, it's not enough to know that there is some kind of relationship between two Parts, I need to know which  kind  of relationship. (Thus the two different fields).
Now, I want to update uses in one object, when another is set to used_in, e.g.: if a.uses(b) I want to automatically set b.used_in(a).

I did this by setting it manually in the form_valid method of my UpdateView --> for example, if a.uses is changed, look for b and change its used_in.

For example:

if 'used_in' in form.changed_data:
    if self.object.used_in:
        other_device = Device.objects.filter(pk= self.object.used_in.pk)[0]
        other_device.uses = self.object
        other_device.save()

However, this has several disadvantages. First of all, I don't really like having to do this manually and was wondering whether this could not be done some other way, but I didn't find anything on Google. The second problem is that one Part can use several other Parts, but with my method, only the last Part that was used is shown.

My question is: Is it somehow possible to connect the two foreign keys inside the model, or shift to only one foreign key, or do this in some other way that makes sense.

Body:
You can try this format :

class Parts(models.Model):
    title = models.CharField(u'Store_Title', max_length=100)
    def __str__(self):
        return self.title

class Partused(models.Model):

    mainpart = models.ForeignKey('Parts', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'mainpart')
    subpart = models.ForeignKey('Parts', null = True, blank = True, on_delete = models.SET_NULL, related_name = 'subpart')
    def __str__(self):
        return self.mainpart.title + 'uses --> ' + self.subpart.title

Search Part :  Parts.objects.get(title = 'Part_to_find')

Search Part Which have subparts :  Partused.objects.filter(mainpart = 'Part_ID')

Search Part Which are subparts to other parts:  Partused.objects.filter(subpart = 'Part_ID')


来源: stackexchange

问:
Remove duplicates in array separated by double commas in JavaScript
I have an array in JavaScript like this

```<code>var data = [,A_1_VII,VII,V2,,A_1_VII,VII,V2,,A_1_VII,VII,V2,,B_1_XIV,XIV,V3,,B_2_XVI,XVI,V3]
</code>```

when I alert in JavaScript it gives as below

,A_1_VII,VII,V2

,A_1_VII,VII,V2

,A_1_VII,VII,V2

,B_1_XIV,XIV,V3

,B_2_XVI,XVI,V3

But I want like this which is duplicates removed array

```<code>var unique_data = [,A_1_VII,VII,V2,,B_1_XIV,XIV,V3,,B_2_XVI,XVI,V3]
</code>```

On alert it should give like this

,A_1_VII,VII,V2

,B_1_XIV,XIV,V3

,B_2_XVI,XVI,V3

答:
First Thing your array contains string as a constant that's not going to work.

Secondly, if all of you value are strings you can do it as follows:

var data =[,"A_1_VII","VII","V2",,"A_1_VII","VII","V2",,"A_1_VII","VII","V2",,"B_1_XIV","XIV","V3",,"B_2_XVI","XVI","V3"];

var uniqueArray = data.filter(function(item, pos) {
    return data.indexOf(item) == pos;
})

alert(uniqueArray);```

ContentLicense: CC BY-SA 3.0

Body:
I have an array in JavaScript like this

var data = [,A_1_VII,VII,V2,,A_1_VII,VII,V2,,A_1_VII,VII,V2,,B_1_XIV,XIV,V3,,B_2_XVI,XVI,V3]

when I alert in JavaScript it gives as below

,A_1_VII,VII,V2

,A_1_VII,VII,V2

,A_1_VII,VII,V2

,B_1_XIV,XIV,V3

,B_2_XVI,XVI,V3

But I want like this which is duplicates removed array

var unique_data = [,A_1_VII,VII,V2,,B_1_XIV,XIV,V3,,B_2_XVI,XVI,V3]

On alert it should give like this

,A_1_VII,VII,V2

,B_1_XIV,XIV,V3

,B_2_XVI,XVI,V3


问:
Reading from CSV file into python
I am doing coursework where it requires me to make a Quiz programme where an account for a user is created and stored to a CSV along with personal information. It then requires me to read from a CSV file and read the questions and answers for the module to run and then it stores the test data to the CSV where all the account information is stored.

I have successfully written to the CSV however I am having a problem with reading correctly.
 The CSV is set up with 2 columns and 5 rows in A1, A2, A3, A4 and A5 is where the questions are stored and in B1, B2, B3, B4 and B5 is where the answers are stored for the question on the row. Currently I am attempting to print the Question into an input and then use an if statement to check it against the answer I have stored in the CSV.

Currently I am having problems with printing everything within the cell and I am having to use ranges. A section of my python code is as follows...

```<code>import csv

with open("questions.csv", 'r') as f:
   for row in f:
       question1 = row[0:94]
       answer1 = row[95]

print(question1)
print(answer1)
</code>```

How do I print the whole cell into the input without having to do the ranges in the row?

答:
in your code, row is a string containing all the cells in the current row separated by comma.

You want to do:

row = row.split(',').rstrip()

So now row[0] will be the whole content of the first col and so on....

Or you can use csv.reader as suggested by @Burhan Khalid

Title: Reading from CSV file into python

Body:
I am doing coursework where it requires me to make a Quiz programme where an account for a user is created and stored to a CSV along with personal information. It then requires me to read from a CSV file and read the questions and answers for the module to run and then it stores the test data to the CSV where all the account information is stored.

I have successfully written to the CSV however I am having a problem with reading correctly.
 The CSV is set up with 2 columns and 5 rows in A1, A2, A3, A4 and A5 is where the questions are stored and in B1, B2, B3, B4 and B5 is where the answers are stored for the question on the row. Currently I am attempting to print the Question into an input and then use an if statement to check it against the answer I have stored in the CSV.

Currently I am having problems with printing everything within the cell and I am having to use ranges. A section of my python code is as follows...

import csv

with open("questions.csv", 'r') as f:
   for row in f:
       question1 = row[0:94]
       answer1 = row[95]

print(question1)
print(answer1)

How do I print the whole cell into the input without having to do the ranges in the row?


问:
Installing pycairo under ubuntu
For some reason I can't get python to find cairo.

When I did ./waf configure I got

```<code>Setting top to                           : /home/user/pycairo/py2cairo-1.10.0
Setting out to                           : /home/user/pycairo/py2cairo-1.10.0/build_directory
./configure()
Checking for 'gcc' (c compiler)          : ok
Checking for program python              : /usr/bin/python
Checking for python version              : (2, 7, 2, 'final', 0)
Checking for library python2.7           : yes
Checking for program python2.7-config    : /usr/bin/python2.7-config
Checking for header Python.h             : yes
Checking for program pkg-config          : /usr/bin/pkg-config
Checking for 'cairo' >= 1.10.0           : yes
Configuration:
PREFIX                                   : /usr/local
LIBDIR                                   : /usr/local/lib
</code>```

So next I ran ./waf install.

tried

```<code>import cairo
ImportError: No module named cairo
</code>```

Now I am pretty stumped on what to do next.
I checked /usr/local/lib/python2.7/site-packages and it is there but that is the only package there. I also noticed "dist-packages" which I think that is where it's meant to go?

any help is greatly appreciated.

答:
I like to suggest its cffi-based version which is more common it seems and can be installed on Ubuntu 17.10 at least from apt-get (or apt)</p>

```<code>sudo apt-get install python-cairocffi python3-cairocffi
</code>```

Title: Installing pycairo under ubuntu

Body:
For some reason I can't get python to find cairo.

When I did ./waf configure I got

Setting top to                           : /home/user/pycairo/py2cairo-1.10.0
Setting out to                           : /home/user/pycairo/py2cairo-1.10.0/build_directory
./configure()
Checking for 'gcc' (c compiler)          : ok
Checking for program python              : /usr/bin/python
Checking for python version              : (2, 7, 2, 'final', 0)
Checking for library python2.7           : yes
Checking for program python2.7-config    : /usr/bin/python2.7-config
Checking for header Python.h             : yes
Checking for program pkg-config          : /usr/bin/pkg-config
Checking for 'cairo' >= 1.10.0           : yes
Configuration:
PREFIX                                   : /usr/local
LIBDIR                                   : /usr/local/lib

So next I ran ./waf install.

tried

import cairo
ImportError: No module named cairo

Now I am pretty stumped on what to do next.
I checked /usr/local/lib/python2.7/site-packages and it is there but that is the only package there. I also noticed "dist-packages" which I think that is where it's meant to go?

any help is greatly appreciated.

Body:
I like to suggest its cffi-based version which is more common it seems and can be installed on Ubuntu 17.10 at least from apt-get (or apt)

sudo apt-get install python-cairocffi python3-cairocffi


问:
How can I specify the download folder for rails system tests using chrome?
My use case here is twofold:

Avoid filling up the standard folder (in my case ~/Downloads) with files generated by system specs.

Ensure unity across build environments when uploading downloaded files.

答:
Pack the following in your spec_helper.rb:

```<code>config.before(:each, type: :system, js: true) do
  desired_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    'chromeOptions' => {
      'prefs' => {
        'download.default_directory' => Rails.root.join('spec/downloads'),
        'download.prompt_for_download' => false,
        'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
      }
    }
  )
  driven_by :selenium, using: :chrome, options: { desired_capabilities: desired_capabilities }
end
</code>```

Et voila!

Body:
Pack the following in your spec_helper.rb:

config.before(:each, type: :system, js: true) do
  desired_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    'chromeOptions' => {
      'prefs' => {
        'download.default_directory' => Rails.root.join('spec/downloads'),
        'download.prompt_for_download' => false,
        'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
      }
    }
  )
  driven_by :selenium, using: :chrome, options: { desired_capabilities: desired_capabilities }
end

Et voila!


问:
How to remove the single quotation mark from a list in Python
I am trying to remove the single quotation marks from this list:

```<code>list = ['amazed, 10']
</code>```

and convert it to

```<code>list = ['amazed', 10]
</code>```

I used list= [x.strip('') for x in list] but it does not work.

Is there a workaround?

Thanks in advance!

答:
You need to split but not strip, as your list contains a single string 'amazed, 10' that expected to be split into 2 items - 'amazed' and 10:

```<code>lst = ['amazed, 10']
lst = [int(i) if i.isdigit() else i for i in lst[0].split(', ')]
print(lst)
</code>```

The output:

```<code>['amazed', 10]
</code>```

Body:
I am trying to remove the single quotation marks from this list:

list = ['amazed, 10']

and convert it to

list = ['amazed', 10]

I used list= [x.strip('') for x in list] but it does not work.

Is there a workaround?

Thanks in advance!

Body:
You need to split but not strip, as your list contains a single string 'amazed, 10' that expected to be split into 2 items - 'amazed' and 10:

lst = ['amazed, 10']
lst = [int(i) if i.isdigit() else i for i in lst[0].split(', ')]
print(lst)

The output:

['amazed', 10]


问:
LocalStorage value not shown in other html page
I have a index.html page where I set userid in localStorage as below

Index.html

```<code><div>
  <input type="text" id='user_id' required tabindex="1" name="user_id" autofocus autocomplete=off placeholder="User Name">
 </div>
 <input class="user_login_submit" type="submit"  id='btnLogin' tabindex="3" name="login_btnSubmit" tabindex='3' onclick='validateLogin();'value="LOGIN" />

<script>
function validateLogin() {
    var userid = document.getElementById('user_id').value;
    localStorage.setItem("userID", "Welcome, " + userid);
}
</script>
</code>```

Now I wanted to show this userid in navbar i.e. nav.html page, Please note it only contains navbar code no any other header or body part,

nav.html

```<code>   <li><a href="#" id="profileDDL"style="text-transform:capitalize;opactiy:0.4;font-weight:bolder">
    </a></li>
    <script>
                   $(function() {
                    $('#profileDDL').innerHTML=localStorage.getItem("userID");
                });
       </script>
</code>```

and now ,  I wanted to load this nav.html page inside user_home.html or any other html page with  userID from localStorage , navbar is loaded fine but not the localStorage value.

user_home.html

```<code>    <body>
        <!--Navigation bar-->
        <div id="nav-placeholder">

        </div>
        <!--end of Navigation bar-->

        <script>
        $(function(){
        $("#nav-placeholder").load("nav.html");
});
</script>
    </body>
</code>```

I hope you understand the what is my problem.I'm stuck here.

答:
Change the line

```<code>$('#profileDDL').innerHTML=localStorage.getItem("userID");
</code>```

to

```<code>$('#profileDDL').html(localStorage.getItem("userID"));
</code>```

Body:
I have a index.html page where I set userid in localStorage as below

Index.html

  <input type="text" id='user_id' required tabindex="1" name="user_id" autofocus autocomplete=off placeholder="User Name">

 <input class="user_login_submit" type="submit"  id='btnLogin' tabindex="3" name="login_btnSubmit" tabindex='3' onclick='validateLogin();'value="LOGIN" />

Now I wanted to show this userid in navbar i.e. nav.html page, Please note it only contains navbar code no any other header or body part,

nav.html

and now ,  I wanted to load this nav.html page inside user_home.html or any other html page with  userID from localStorage , navbar is loaded fine but not the localStorage value.

user_home.html

I hope you understand the what is my problem.I'm stuck here.

Body:
Change the line

$('#profileDDL').innerHTML=localStorage.getItem("userID");

to

$('#profileDDL').html(localStorage.getItem("userID"));


问:
Align content in the middle of div
I'd like to align the content of my second column in the middle of the div. I did try in a lot of different ways but so far I haven't found how.

I'm using Bootstrap 4.

Could you tell me how to do it ?

```<code><div class="card">
   <div class="card-body">
      <div class="row">
         <div class="col-md-1">
            <img class="rounded-circle img-thumbnail d-inline"
                 src="..."
                 height="65px"
                 width="65px"
                 alt="User image">
         </div>
         <div class="col-md-11">
            <p class="d-inline">...</p>
            <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
         </div>
      </div>
   </div>
</div>
</code>```

I'm sure I miss something very simple but don't know what.

JSFiddle exemple

Thanks for your help :)

答:
To get it vertically center</p>

```<code><div class="col-md-11 align-self-center">
    <p class="d-inline">Kitten</p>
    <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
</div>
</code>```

Title: Align content in the middle of div

Body:
I'd like to align the content of my second column in the middle of the div. I did try in a lot of different ways but so far I haven't found how.

I'm using Bootstrap 4.

Could you tell me how to do it ?

...

            <button class="close" type="button"></button>

I'm sure I miss something very simple but don't know what.

JSFiddle exemple

Thanks for your help :)

Body:
To get it vertically center

<div class="col-md-11 align-self-center">
    <p class="d-inline">Kitten</p>
    <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
</div>


问:
Spring et hibernate : org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode
I am preparing to do a web service project but before I started I decided to understand the principle. For that I developed an application that launches well in eclipse but as soon as I try to access from the browser I have this exception in the eclipse console:

```<code>java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.prepareTransaction(HibernateJpaDialect.java:119)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:111)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy63.findAll(Unknown Source)
at source.TypeServiceImpl.getAllTypes(TypeServiceImpl.java:18)
at source.TypeController.getAllTypes(TypeController.java:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at source.CorsFilter.doFilterInternal(CorsFilter.java:20)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:844)
</code>```

and in the browser I have this message:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

  Mon Nov 13 03:23:18 WAT 2017

  There was an unexpected error (type=Internal Server Error, status=500).
  Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;

I specify that I work with hivernate 5.2.12, spring 4.0.6 and sqlite 3. I may say that hivernate 5.2.12 is incompatible with spring 4.0.6.

When I changed the version of spring to 4.3.12 I have the following exception:

```<code>Caused by: org.hibernate.MappingException: org.hibernate.dialect.SQLiteDialect does not support sequences
at org.hibernate.dialect.Dialect.getDropSequenceString(Dialect.java:934) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.dialect.Dialect.getDropSequenceStrings(Dialect.java:916) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlDropStrings(StandardSequenceExporter.java:41) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlDropStrings(StandardSequenceExporter.java:18) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:249) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:313) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
... 22 common frames omitted
</code>```

I thank you in advance for your help.

答:
org.hibernate.dialect.SQLiteDialect does not support sequences

This means that you shouldn't use sequences (to generate id) with SQLite.

Body:
I am preparing to do a web service project but before I started I decided to understand the principle. For that I developed an application that launches well in eclipse but as soon as I try to access from the browser I have this exception in the eclipse console:

java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.prepareTransaction(HibernateJpaDialect.java:119)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:111)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy63.findAll(Unknown Source)
at source.TypeServiceImpl.getAllTypes(TypeServiceImpl.java:18)
at source.TypeController.getAllTypes(TypeController.java:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at source.CorsFilter.doFilterInternal(CorsFilter.java:20)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:844)

and in the browser I have this message:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

  Mon Nov 13 03:23:18 WAT 2017

  There was an unexpected error (type=Internal Server Error, status=500).
  Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;

I specify that I work with hivernate 5.2.12, spring 4.0.6 and sqlite 3. I may say that hivernate 5.2.12 is incompatible with spring 4.0.6.

When I changed the version of spring to 4.3.12 I have the following exception:

Caused by: org.hibernate.MappingException: org.hibernate.dialect.SQLiteDialect does not support sequences
at org.hibernate.dialect.Dialect.getDropSequenceString(Dialect.java:934) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.dialect.Dialect.getDropSequenceStrings(Dialect.java:916) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlDropStrings(StandardSequenceExporter.java:41) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlDropStrings(StandardSequenceExporter.java:18) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:249) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:313) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889) ~[hibernate-core-5.2.12.Final.jar:5.2.12.Final]
... 22 common frames omitted

I thank you in advance for your help.


问:
How do I hide the header in a WPF Expander?
I have a business requirement that when the user clicks a series of checkboxes in a WPF application that it will show panels depending upon what checkboxes they select.  I would like to use the expander panel but I am not sure how to hide the header.  The user should not be allowed to see it unless they check the checkbox.  Does anyone know?</p>

答:
While not the ideal approach you could go this route...

```<code>    <Expander>
        <Expander.Header>
            <TextBlock Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}, Mode=FindAncestor},
                 Converter={StaticResource BoolToVisibilityConverter}}">My Expander</TextBlock>
        </Expander.Header>
    </Expander>
</code>```

...where BoolToVisibilityConverter is something like...

```<code>    public class BoolToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value)
                return Visibility.Visible;
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((Visibility)value == Visibility.Visible)
                return true;
            return false;
        }

        #endregion
    }
</code>```

ContentLicense: CC BY-SA 2.5

Body:
While not the ideal approach you could go this route...

    <Expander>
        <Expander.Header>
            <TextBlock Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}, Mode=FindAncestor},
                 Converter={StaticResource BoolToVisibilityConverter}}">My Expander</TextBlock>
        </Expander.Header>
    </Expander>

...where BoolToVisibilityConverter is something like...

    public class BoolToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value)
                return Visibility.Visible;
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((Visibility)value == Visibility.Visible)
                return true;
            return false;
        }

        #endregion
    }


Title: How to remove the single quotation mark from a list in Python

Body:
You can try:

>>> l = ['amazed, 10']
>>> l = l[0].split(", ")
>>> l
['amazed', ' 10']


问:
Facebook App Invites is deprecated
As the latest release of Facebook SDK version 4.28.0 - November 7, 2017, App Invites is deprecated.
https://developers.facebook.com/docs/app-invites/android/

With the release of the Facebook SDK version 4.28.0, App Invites is
  deprecated. It will be supported until February 5, 2018.

It makes the AppInviteDialog not working as expected (show white screen instead of list friends - Facebook app is not installed in the device), even I decreased Facebook SDK version to 4.27.0 or lower).
I tried to find out more information at offical docs but no luck.
Anyone have a solution for this trouble ?

答:
Seems there is no other option for non-game applications but to remove  Facebook app invites.
Google Firebase invites is good option we integrated recently and used side-by-side with Facebook Invites. </p>

Title: Facebook App Invites is deprecated


问:
How make modeling from train and test data?
I have data in the order file,

```<code>#split into train and test sets
X = DataFrame.values
train_size = int(len(X)*0.66)
train, test = X[1:train_size], X[train_size:]
train_X, train_y = train[:,0], train[:,1]
test_X, test_y = test[:,0], test[:,1]
</code>```

I want train_data to test data in different files by calling.

```<code>def test(learning_rate=0.1, k=1, training_epochs=15):
    print ('... loading data')
    datasets = ('book-sales.csv')
    train_X, train_y = datasets[0]
    test_X, test_y = datasets[0]
    print ('... modeling')
    rbm = RBM(input=train_X, n_visible=28 * 28, n_hidden=500)
</code>```

I tried but I found this message.

train_X, train_y = datasets[0]

ValueError: not enough values to unpack (expected 2, got 1)

How should I write it?

答:
When you have to read a dataset directly in a file, it is recommended to use the library pandas http://pandas.pydata.org/ because it has been designed for data analysis:

```<code>import pandas as pd
data_path = "./book-sales.csv" #path to access data
datasets = pd.read_csv(data_path)
</code>```

datasets object has now the DataFrame pandas type.

Plus, depending on the actual form of your dataset, you may want to use the get_values method datasets.get_values(), and reshape for better convenience.

That way, you can split your data into train and test sets.

Hope this could be helpfull

Body:
I have data in the order file,

#split into train and test sets
X = DataFrame.values
train_size = int(len(X)*0.66)
train, test = X[1:train_size], X[train_size:]
train_X, train_y = train[:,0], train[:,1]
test_X, test_y = test[:,0], test[:,1]

I want train_data to test data in different files by calling.

def test(learning_rate=0.1, k=1, training_epochs=15):
    print ('... loading data')
    datasets = ('book-sales.csv')
    train_X, train_y = datasets[0]
    test_X, test_y = datasets[0]
    print ('... modeling')
    rbm = RBM(input=train_X, n_visible=28 * 28, n_hidden=500)

I tried but I found this message.

train_X, train_y = datasets[0]

ValueError: not enough values to unpack (expected 2, got 1)

How should I write it?

Body:
When you have to read a dataset directly in a file, it is recommended to use the library pandas http://pandas.pydata.org/ because it has been designed for data analysis:

import pandas as pd
data_path = "./book-sales.csv" #path to access data
datasets = pd.read_csv(data_path)

datasets object has now the DataFrame pandas type.

Plus, depending on the actual form of your dataset, you may want to use the get_values method datasets.get_values(), and reshape for better convenience.

That way, you can split your data into train and test sets.

Hope this could be helpfull


问:
MySQL how to do an if exist increment in a single query
I just wish to have a table to store a number of events by day.

Given a table:

```<code>create table totals (
    entryday date,
    total int(11) default 0 not null,
    primary key (entryday) );
</code>```

How can I write a simple query which increments, but creates an necessary?

I tried this - but it is not incrementing (it remains at 1):

```<code>REPLACE totals SET total = total + 1, entryday = "08-01-11"
</code>```

Obviously this could be done in 2 queries quite simply, but it's through JDBC calls and may be called many times, so 1 query would be better.

答:
For MySQL 5.0+, see INSERT ON DUPLICATE KEY UPDATE.</p>

```<code>INSERT INTO totals (entryday, total) VALUES ("08-01-11", 1)
  ON DUPLICATE KEY UPDATE total=total+1;
</code>```

Body:
I just wish to have a table to store a number of events by day.

Given a table:

create table totals (
    entryday date,
    total int(11) default 0 not null,
    primary key (entryday) );

How can I write a simple query which increments, but creates an necessary?

I tried this - but it is not incrementing (it remains at 1):

REPLACE totals SET total = total + 1, entryday = "08-01-11"

Obviously this could be done in 2 queries quite simply, but it's through JDBC calls and may be called many times, so 1 query would be better.

Body:
For MySQL 5.0+, see INSERT ON DUPLICATE KEY UPDATE.

INSERT INTO totals (entryday, total) VALUES ("08-01-11", 1)
  ON DUPLICATE KEY UPDATE total=total+1;


问:
VS Code extension installation without admin rights
I am thinking of asking my IT-Department of gaining the right to install VS-Studio Code, and using it with some extensions. Like Python.

My Question is: Can I install the extensions without having to use an admin user, under windows?

I got this exact Problem with Notepad++, where i can only install the Editor, via the Software deployment tool, but not the extensions(via the editor myself).

答:
You have the option to unpack the zip file and use the editor without running the installer. You will lack some features like 'Open with Code' in the contextmenu of the file explorer.

Windows setup without installer


问:
Why if open popup, theTextarea is less than the text in it?
I have text area:

function textAreaAdjust(o) {
    o.style.height = "1px";
    o.style.height = (25 + o.scrollHeight) + "px";
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>textarea#commentText {
        height: auto;
        width: 570px!important;
 }</code>```

<textarea name="bookId" id="commentText" value="" class="form-control" ng-maxlength="1000" maxlength="1000" rows="3" onkeyup="textAreaAdjust(this)" style="overflow:hidden"></textarea>

        ```

And if i open popup window, I get such a result:

How do I make the required textarea size when I open it?
I specified the auto size in css but nothing happened.

答:
Here use this. Instead of using onkeyup use onfocus on textarea. And manually trigger the focus when you open the popup using javascript. Previously it was only working only when the keyup event was triggered.

document.getElementById("commentText").value = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";

function textAreaAdjust(o) {
    o.style.height = "1px";
    o.style.height = (25 + o.scrollHeight) + "px";
}

document.getElementById("commentText").focus();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>textarea#commentText {
        height: auto;
        width: 570px!important;
 }</code>```

<textarea name="bookId" id="commentText" value="" class="form-control" ng-maxlength="1000" maxlength="1000" rows="3" onfocus="textAreaAdjust(this)" style="overflow:hidden"></textarea>

        ```

Body:
I have text area:

function textAreaAdjust(o) {
    o.style.height = "1px";
    o.style.height = (25 + o.scrollHeight) + "px";
}

textarea#commentText {
        height: auto;
        width: 570px!important;
 }

<textarea name="bookId" id="commentText" value="" class="form-control" ng-maxlength="1000" maxlength="1000" rows="3" onkeyup="textAreaAdjust(this)" style="overflow:hidden"></textarea>

And if i open popup window, I get such a result:

How do I make the required textarea size when I open it?
I specified the auto size in css but nothing happened.

Body:
Here use this. Instead of using onkeyup use onfocus on textarea. And manually trigger the focus when you open the popup using javascript. Previously it was only working only when the keyup event was triggered.

document.getElementById("commentText").value = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";

function textAreaAdjust(o) {
    o.style.height = "1px";
    o.style.height = (25 + o.scrollHeight) + "px";
}

document.getElementById("commentText").focus();

textarea#commentText {
        height: auto;
        width: 570px!important;
 }

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<textarea name="bookId" id="commentText" value="" class="form-control" ng-maxlength="1000" maxlength="1000" rows="3" onfocus="textAreaAdjust(this)" style="overflow:hidden"></textarea>


答:
You probably want ON DUPLICATE KEY:

```<code>INSERT INTO totals (entryday, total)
VALUES ("08-01-11", 1)
ON DUPLICATE KEY UPDATE total = total + 1
</code>```

That'll set the "08-01-11" total to 1 if a row doesn't already exist for that date and increment the total by 1 if it does.

Title: MySQL how to do an if exist increment in a single query

Body:
You probably want ON DUPLICATE KEY:

INSERT INTO totals (entryday, total)
VALUES ("08-01-11", 1)
ON DUPLICATE KEY UPDATE total = total + 1

That'll set the "08-01-11" total to 1 if a row doesn't already exist for that date and increment the total by 1 if it does.


问:
NoSuchMethodError when adding basic authentication in Spring Boot Soap Web service project
Collegues, i am trying to add basic authentication into my SOAP WS (Spring Boot Ppoject). POM lools like:

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>ws-signer</artifactId>
    <packaging>jar</packaging>
    <name>ws-signer</name>
    <version>1.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <project.build.sourceJre>1.8</project.build.sourceJre>
        <project.build.targetJre>1.8</project.build.targetJre>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>com.acap</groupId>
            <artifactId>doc-signer</artifactId>
            <version>1.0-RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- spring-boot-maven-plugin -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
              <!--  <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.6.RELEASE</version>
                    </dependency>
                </dependencies>-->
            </plugin>
            <!-- maven-jaxb2-plugin -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
</code>```

As i said I would like to add basic authentication to my soap web service.
As i understand i need to add next dependency:

```<code><dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-security</artifactId>
     </dependency>
</code>```

But if i add this dependency and call mvn spring-boot:run than exception occured:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot
  instantiate interface
  org.springframework.boot.SpringApplicationRunListener :
  org.springframework.boot.context.event.EventPublishingRunListener     at
  org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)
    at
  org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
    at
  org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:378)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:291)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at
  com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)
  Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate
  [org.springframework.boot.context.event.EventPublishingRunListener]:
  Constructor threw exception; nested exception is
  java.lang.NoSuchMethodError:
  org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
    at
  org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)
    ... 6 more Caused by: java.lang.NoSuchMethodError:
  org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at
  org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)
    at
  org.springframework.boot.context.event.EventPublishingRunListener.(EventPublishingRunListener.java:56)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
  Method)   at
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
    ... 7 more

Dependency tree is:

```<code>-- maven-dependency-plugin:2.10:tree (default-cli) @ ws-signer ---
[INFO] org.springframework.boot:ws-signer:jar:1.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
[INFO] |  |  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework.ws:spring-ws-core:jar:2.4.0.RELEASE:compile
[INFO] |     \- org.springframework.ws:spring-xml:jar:2.4.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.8.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.12.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.8.RELEASE:compile
[INFO] +- com.acap:doc-signer:jar:1.0-RELEASE:compile
[INFO] +- com.github.ulisesbocchio:jasypt-spring-boot-starter:jar:1.16:compile
[INFO] |  \- com.github.ulisesbocchio:jasypt-spring-boot:jar:1.16:compile
[INFO] |     \- org.jasypt:jasypt:jar:1.9.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.3.12.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile
</code>```

UPDATE

I delete

```<code><dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
</code>```

and added

```<code>   <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>1.5.8.RELEASE</version>
            </dependency>
</code>```

Than I rewrite @Component which send mails.

UPDATE 2

Change places for dependencies:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

and

```<code><dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
</dependency>
</code>```

no dependcies tree looks like :

```<code>[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile
</code>```

Stacktrace (after spring-boot:run) is

```<code>17:14:42.118 ERROR [restartedMain] o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:248)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 21 common frames omitted
</code>```

I will be appriciate for any help.

UPDATE - DECISION

My problem was in the sequence of dependencies in the pom file.
It was necessary to raise <artifactId> spring-boot-starter-security </ artifactId> above (it should be near other dependenvies with org.springframework.boot group id).
The correct POM file in my case should look like this:

```<code> <dependencies>

        <!-- spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
          </dependency>

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>

         <!-- other dependecies -->

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>
</code>```

答:
In the dependency tree - Why spring-boot-starter-security-1.5.8.. shows under commons-io ?

```<code>[INFO] +- commons-io:commons-io:jar:2.5:compile [INFO]
    \- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
</code>```

So the problem in your POM is dependency sequence.

Body:
Collegues, i am trying to add basic authentication into my SOAP WS (Spring Boot Ppoject). POM lools like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>ws-signer</artifactId>
    <packaging>jar</packaging>
    <name>ws-signer</name>
    <version>1.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <project.build.sourceJre>1.8</project.build.sourceJre>
        <project.build.targetJre>1.8</project.build.targetJre>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>com.acap</groupId>
            <artifactId>doc-signer</artifactId>
            <version>1.0-RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

As i said I would like to add basic authentication to my soap web service.
As i understand i need to add next dependency:

<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-security</artifactId>
     </dependency>

But if i add this dependency and call mvn spring-boot:run than exception occured:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot
  instantiate interface
  org.springframework.boot.SpringApplicationRunListener :
  org.springframework.boot.context.event.EventPublishingRunListener     at
  org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)
    at
  org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
    at
  org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:378)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:291)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at
  com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)
  Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate
  [org.springframework.boot.context.event.EventPublishingRunListener]:
  Constructor threw exception; nested exception is
  java.lang.NoSuchMethodError:
  org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
    at
  org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)
    ... 6 more Caused by: java.lang.NoSuchMethodError:
  org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at
  org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)
    at
  org.springframework.boot.context.event.EventPublishingRunListener.(EventPublishingRunListener.java:56)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
  Method)   at
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
    ... 7 more

Dependency tree is:

-- maven-dependency-plugin:2.10:tree (default-cli) @ ws-signer ---
[INFO] org.springframework.boot:ws-signer:jar:1.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
[INFO] |  |  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework.ws:spring-ws-core:jar:2.4.0.RELEASE:compile
[INFO] |     \- org.springframework.ws:spring-xml:jar:2.4.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.8.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.12.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.8.RELEASE:compile
[INFO] +- com.acap:doc-signer:jar:1.0-RELEASE:compile
[INFO] +- com.github.ulisesbocchio:jasypt-spring-boot-starter:jar:1.16:compile
[INFO] |  \- com.github.ulisesbocchio:jasypt-spring-boot:jar:1.16:compile
[INFO] |     \- org.jasypt:jasypt:jar:1.9.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.3.12.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile

UPDATE

I delete

<dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

and added

   <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>1.5.8.RELEASE</version>
            </dependency>

Than I rewrite @Component which send mails.

UPDATE 2

Change places for dependencies:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

and

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
</dependency>

no dependcies tree looks like :

[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile

Stacktrace (after spring-boot:run) is

17:14:42.118 ERROR [restartedMain] o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:248)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 21 common frames omitted

I will be appriciate for any help.

UPDATE - DECISION

My problem was in the sequence of dependencies in the pom file.
It was necessary to raise <artifactId> spring-boot-starter-security </ artifactId> above (it should be near other dependenvies with org.springframework.boot group id).
The correct POM file in my case should look like this:

 <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
          </dependency>

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>

Body:
In the dependency tree - Why spring-boot-starter-security-1.5.8.. shows under commons-io ?

[INFO] +- commons-io:commons-io:jar:2.5:compile [INFO]
    \- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile

So the problem in your POM is dependency sequence.


问:
How to transfer the control from one part of the main to another part of the main in java?
I was writing a program which required me to display a set of statements to the

user then ask him whether he would like to return to the main screen.

But since I was using a case I could not transfer control back to the code before it.I want to know how I can do it.Here's the code:

```<code>    import java.io.*;
    public class main
    {
       public static void main() throws IOException
       {
            InputStreamReader isr=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(isr);
            System.out.println("START");
            int ch=Integer.parseInt(br.readLine());
            switch(ch)
            {
                 case 1:System.out.println("HI");
                        break;
                       /*I want a way to transfer the control from the case
                         such that it is transferred to
                         the print statement START.*/

            }
       }
    }
</code>```

答:
There are many ways to do that. One would be to have it in a loop and keep asking the user whether he wants to have a new input.

```<code>    import java.io.*;
    public class main
  {
  public static void main() throws IOException
  {
    InputStreamReader isr=new InputStreamReader(System.in);
    BufferedReader br=new BufferedReader(isr);
    int ch;
    int input;
    while(true)
    {
    System.out.println("Do you want to return to main screen. Press 1 for Yes, 0 for No");
    input = Integer.parseInt(br.readLine());
    if(input == 1)
    {
     ch=Integer.parseInt(br.readLine());
        switch(ch)
        {
             case 1:System.out.println("HI");
                    break;
        }
    }
    else
    {
    break;
    }
    }
</code>```

Even the answer above mine is correct but this might give user more usability.
Hope this helps !!

Body:
I was writing a program which required me to display a set of statements to the

user then ask him whether he would like to return to the main screen.

But since I was using a case I could not transfer control back to the code before it.I want to know how I can do it.Here's the code:

    import java.io.*;
    public class main
    {
       public static void main() throws IOException
       {
            InputStreamReader isr=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(isr);
            System.out.println("START");
            int ch=Integer.parseInt(br.readLine());
            switch(ch)
            {
                 case 1:System.out.println("HI");
                        break;
                       /*I want a way to transfer the control from the case
                         such that it is transferred to
                         the print statement START.*/

            }
       }
    }

Body:
There are many ways to do that. One would be to have it in a loop and keep asking the user whether he wants to have a new input.

    import java.io.*;
    public class main
  {
  public static void main() throws IOException
  {
    InputStreamReader isr=new InputStreamReader(System.in);
    BufferedReader br=new BufferedReader(isr);
    int ch;
    int input;
    while(true)
    {
    System.out.println("Do you want to return to main screen. Press 1 for Yes, 0 for No");
    input = Integer.parseInt(br.readLine());
    if(input == 1)
    {
     ch=Integer.parseInt(br.readLine());
        switch(ch)
        {
             case 1:System.out.println("HI");
                    break;
        }
    }
    else
    {
    break;
    }
    }

Even the answer above mine is correct but this might give user more usability.
Hope this helps !!


问:
How many partitions should I create for kafka consumers?
Currently I am having only one partition of topic and only one consumer.
But my consumer runs slow so I want to add new consumers to the same topic.

But at the same time I also want all the consumers to process exclusive set of messages.

I am not able to determine how many partitions should I create so that I can add consumers whenever I want to increase throughput and to process exclusive messages.

答:
If you have N partitions for a topic, you can start a consumer group with N consumers, and they will each get to work on one of the partitions.

Each consumer will get a disparate set of messages (unless there is fail-over involved, then some messages may be delivered more than once) that way, and if the workload is evenly spread amongst all partitions, this will load-balance properly.

If you have fewer than N consumers, some of them will get more than one partition, but they will still not share partitions and each will get roughly the same number of partitions.

If you have more than N consumers, some will stay idle (but can act as hot standbys in case one of the others drops out).

The key to all this is that you put these consumers into the same consumer group. That is the way to indicate to Kafka that they should divide the partitions between them. If you started N consumer groups instead, each group would get all messages in parallel (each message would be processed N times).

The main downside to partitioning is that you lose the total ordering of messages. Messages are delivered in-order only with respect to other messages in the same partition. This may or may not be a problem for your application (and if it is, you can re-arrange things in your application by looking at timestamps).


问:
Sort the odd numbers in the list
How can I sort ascending the odd numbers in a list of integers, but leaving the even numbers in their original places?

Example:

```<code>sortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4]
</code>```

My code:

```<code>def sort_array(source_array):
    odd_numbers = [n for n in source_array if n%2!=0]
    odd_numbers = sorted(odd_numbers)
</code>```

How do I switch the indices of the odd numbers in source_array with the ones in odd_numbers?

答:
```<code>def sort_array(source_array):
    odd_numbers = sorted([n for n in source_array if n%2!=0])
    c = 0
    res = []
    for i in source_array:
        if i %2!=0:
            res.append(odd_numbers[c])
            c += 1
        else:
            res.append(i)
    return res
</code>```

Title: Sort the odd numbers in the list

Body:
How can I sort ascending the odd numbers in a list of integers, but leaving the even numbers in their original places?

Example:

sortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4]

My code:

def sort_array(source_array):
    odd_numbers = [n for n in source_array if n%2!=0]
    odd_numbers = sorted(odd_numbers)

How do I switch the indices of the odd numbers in source_array with the ones in odd_numbers?


问:
ember Error: Compile Error: is not a helper
I got the following error while developing our front-end with Ember.js:

ember Error: Compile Error: '...' is not a helper

What is the meaning of this error?

答:
Reason

Ember throws this error if there is no component or helper with the given name is not found in your project or your dependent addons.

How to solve

You should check the name of the component or helper that you have written (possible errors are spelling errors or writing directory structure of the component incorrectly).

This twiddle shows example of this error message when the component my-component is called as {{my-component2 x=x}} instead of {{my-component x=x}} mistakenly.


问:
VBA prevent closing of UserForm with "End" in code
In my spreadsheet, I have a UserForm that is supposed to be open at all times.

Once in a while, my code will contain an "End" where I exit the code based on some if statement.

The problem is that this closes the UserForm, is there a way to prevent this from happening?

EDIT:

```<code>Sub Test1()
    'Random code
    Call Test2(Variable)
    'Random code
End Sub

Sub Test2(ByVal Variable as Double)
    If Variable = 0 then
        'Random code
    End If
    If Variable = 1 then
        Call Test3
        End 'Original placement of End
    End If
End Sub

Sub Test3()
    'Random code
End Sub
</code>```

This is a rough example of how the code is build (its rather long at this point). So depending on the "variable" different things happen in Test2. But if the Variable is 1, then the "random code" back in Test1 can't be executed thus, so I have to stop the code. I tried replace "End" with "Exit Sub" this only stops the code in Test2 from running, is it will give me an error when it goes back to Test1.

EDIT2:
Test1() is actually four different subs (at this point, more will be added) that all call Test2(). That is why I choose to split it up into so many subs and call them from within the subs.

答:
End closes anything and kills all the variables and objects that you have.

This is probably the worst way to end any sub and most probably you do not need it.

What's the deference between "end" and "exit sub" in VBA?

https://msdn.microsoft.com/VBA/Language-Reference-VBA/articles/end-statement

Body:
In my spreadsheet, I have a UserForm that is supposed to be open at all times.

Once in a while, my code will contain an "End" where I exit the code based on some if statement.

The problem is that this closes the UserForm, is there a way to prevent this from happening?

EDIT:

Sub Test1()
    'Random code
    Call Test2(Variable)
    'Random code
End Sub

Sub Test2(ByVal Variable as Double)
    If Variable = 0 then
        'Random code
    End If
    If Variable = 1 then
        Call Test3
        End 'Original placement of End
    End If
End Sub

Sub Test3()
    'Random code
End Sub

This is a rough example of how the code is build (its rather long at this point). So depending on the "variable" different things happen in Test2. But if the Variable is 1, then the "random code" back in Test1 can't be executed thus, so I have to stop the code. I tried replace "End" with "Exit Sub" this only stops the code in Test2 from running, is it will give me an error when it goes back to Test1.

EDIT2:
Test1() is actually four different subs (at this point, more will be added) that all call Test2(). That is why I choose to split it up into so many subs and call them from within the subs.