When we develop web applications, a very common problem is that sometimes we don't know what is using the current port that we need. And we cann't start our server while getting this kind of exception:
First we could look at the Task Manager to see whether we can get the process which is using this port. But what if we got nothing? Kill every suspects? It's dangerous and sometimes doesn't help at all.
Restart the computer? Ohh that'll work, that's also what I did previously but it's so out!!! It's so painful to restart everything and it's really unneccessary.
Now I get one solution, which is very easy and helpful.
For example, I want to user port "8080" but it's in use by unknown process.
First open the cmd, execute => netstat -aon|findstr "8080"
Then you'll get result like this:
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       87460
  TCP    [::]:8080                 [::]:0                    LISTENING       87460
Now we know who is using the port, the process with PID "87460".
Then in the cmd, we execute => taskkill /pid 87460 -f
Then you'll get result like this:
SUCCESS: The process with PID 87460 has been terminated.
That's it! Then you retart the server, everything will be fine.
12/05/2013
12/03/2013
[MongoDB-Escape dots '.' in map key] Resolve org.springframework.data.mapping.model.MappingException: Map key foo.map.key contains dots but no replacement was configured!
Sometimes we need to save map into MongoDB. But the key of the map cannot have dots inside its keys.
If the key has dot(s), by default we'll get this kind of exception:
Refer to the source code:
So the solution is configure the property mapKeyDotReplacement for bean MappingMongoConverter in the spring config file.
For example:
What needs to be mentioned is that, the value that we set for "mapKeyDotReplacement" must follow the regular pattern's rule. If use reserved character, must use '\\' to translate it.
If the key has dot(s), by default we'll get this kind of exception:
org.springframework.data.mapping.model.MappingException: Map key foo.bar.key contains dots but no replacement was configured! Make sure map keys don't contain dots in the first place or configure an appropriate replacement! at org.springframework.data.mongodb.core.convert.MappingMongoConverter.potentiallyEscapeMapKey(MappingMongoConverter.java:622) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeMapInternal(MappingMongoConverter.java:586) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createMap(MappingMongoConverter.java:517) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:424) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:386) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:257) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:373) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:451) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:386) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:257) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:373) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:451) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:386) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:257) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:373) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:345) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:310) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:77) at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:859) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:806) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:794)
Refer to the source code:
Spring => "MappingMongoConverter.java"
/** * Potentially replaces dots in the given map key with the configured map key replacement if configured or aborts * conversion if none is configured. * * @see #setMapKeyDotReplacement(String) * @param source * @return */ protected String potentiallyEscapeMapKey(String source) { if (!source.contains(".")) { return source; } if (mapKeyDotReplacement == null) { throw new MappingException(String.format("Map key %s contains dots but no replacement was configured! Make " + "sure map keys don't contain dots in the first place or configure an appropriate replacement!", source)); } return source.replaceAll("\\.", mapKeyDotReplacement); }
So the solution is configure the property mapKeyDotReplacement for bean MappingMongoConverter in the spring config file.
For example:
<bean id="mongoMoxydomainConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter"> <constructor-arg index="0" ref="mongoDbFactory" /> <constructor-arg index="1"> <bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" /> </constructor-arg> <property name="mapKeyDotReplacement" value="\\+"/> </bean>
What needs to be mentioned is that, the value that we set for "mapKeyDotReplacement" must follow the regular pattern's rule. If use reserved character, must use '\\' to translate it.
11/01/2013
[Date Formatting] Java Default Engine AND Joda framework
A formatting string describes how date/time values should be read and written from(to) string representation
Now we compare the two kinds of formatting engines.
 
****************************
Java Default:
****************************
1.1 Date Format Pattern Syntax (Java)
 
The number of symbol letters you specify also determines the format. For example, if the "zz" pattern results in "PDT", then the "zzzz" pattern generates "Pacific Daylight Time". The following table summarizes these rules:
1.2 Rules for Date Format Usage (Java)
 
Examples:
1.3 Date and Time Format Patterns and Results (Java)
 
****************************
JODA:
****************************
2.1 Date Format Pattern Syntax (Joda)
 
We can see from above table, although actual format strings for Java and Joda are almost 100% compatible with each other, still there are differences. The 'F' in default java is not supported in Joda.
Basically, 'F' means 'Day of week in month', for example, '2013-11-8' is the second friday in Nov of 2013, so 'F' will get 2 as result. While 'E' means 'Day of week' only, with the same example, '2013-11-8', 'E' will get 5 as result, because it's Friday, the fifth day in the week.
The number of symbol letters you specify also determines the format. The following table summarizes these rules:
2.2 Rules for Date Format Usage (Joda)
 
For more details, the official docs are the best place to go.
Reference:
Micosoft: StandardDate and Time Format Strings
Now we compare the two kinds of formatting engines.
| 
Engine | 
Formatter 
Thread-safe? | 
Description | 
Example | 
| 
Java | 
SimpleDateFormat 
NO | 
Standard Java date implementation.
  Provides lenient, error-prone and full-featured parsing and writing. It has
  moderate speed and is generally a good choice unless you need to work with
  large quantities of date/time fields. For advanced study please refer to Java SimpleDateFormat documentation. | 
yyyy-MM-dd HH:mm:ss | 
| 
Joda | 
DateTimeFormat 
DateTimeFormatter 
YES | 
An improved third-party date
  library. Joda is stricter on input data accuracy when parsing and does not
  work well with time zones. It does, however, provide a 20-30% speed increase
  compared to standard Java. For further reading please visit the project site
  at http://joda-time.sourceforge.net). 
Joda may be convenient for AS/400
  machines. 
On the other hand, Joda is unable
  to read time zone expressed with any number of z letters and/or at least
  three Z letters
  in a pattern. | 
yyyy-MM-dd HH:mm:ss | 
****************************
Java Default:
****************************
1.1 Date Format Pattern Syntax (Java)
| 
Letter | 
Date or Time Component | 
Presentation | 
Examples | 
| 
G | 
Era designator | 
Text | 
AD | 
| 
Y | 
Year | 
Year | 
1996; 96 | 
| 
M | 
Month in year | 
Month | 
July; Jul; VII; 07; 7 | 
| 
w | 
Week in year | 
Number | 
27 | 
| 
W | 
Week in month | 
Number | 
2 | 
| 
D | 
Day in year | 
Number | 
189 | 
| 
d | 
Day in month | 
Number | 
10 | 
| 
F | 
Day of week in month | 
Number | 
2 | 
| 
E | 
Day in week | 
Text | 
Tuesday; Tue | 
| 
a | 
Am/pm marker | 
Text | 
PM | 
| 
H | 
Hour in day (0-23) | 
Number | 
0 | 
| 
k | 
Hour in day (1-24) | 
Number | 
24 | 
| 
K | 
Hour in am/pm (0-11) | 
Number | 
0 | 
| 
h | 
Hour in am/pm (1-12) | 
Number | 
12 | 
| 
m | 
Minute in hour | 
Number | 
30 | 
| 
s | 
Second in minute | 
Number | 
55 | 
| 
S | 
Millisecond | 
Number | 
970 | 
| 
z | 
Time zone | 
General time zone | 
Pacific Standard Time; PST;
  GMT-08:00 | 
| 
Z | 
Time zone | 
RFC 822 time zone | 
-0800 | 
| 
' | 
Escape for text/id | 
Delimiter | 
(none) | 
| 
'' | 
Single quote | 
Literal | 
' | 
The number of symbol letters you specify also determines the format. For example, if the "zz" pattern results in "PDT", then the "zzzz" pattern generates "Pacific Daylight Time". The following table summarizes these rules:
1.2 Rules for Date Format Usage (Java)
| 
Presentation | 
Processing | 
Number of Pattern Letters | 
Form | 
| 
Text | 
Formatting | 
1 - 3 | 
short or abbreviated form, if one
  exists | 
| 
Text | 
Formatting | 
>= 4 | 
full form | 
| 
Text | 
Parsing | 
>= 1 | 
both forms | 
| 
Year | 
Formatting | 
2 | 
truncated to 2 digits | 
| 
Year | 
Formatting | 
1 or >= 3 | 
interpreted as Number. | 
| 
Year | 
Parsing | 
1 | 
intepreted literally | 
| 
Year | 
Parsing | 
2 | 
interpreted relative to the
  century within 80 years before or 20 years after the time when theSimpleDateFormat instance
  is created | 
| 
Year | 
Parsing | 
>= 3 | 
intepreted literally | 
| 
Month | 
Both | 
1-2 | 
interpreted as a Number | 
| 
Month | 
Parsing | 
>= 3 | 
interpreted as Text (using Roman
  numbers, abbreviated month name - if exists, or full month name) | 
| 
Month | 
Formatting | 
3 | 
interpreted as Text (using Roman
  numbers, or abbreviated month name - if exists) | 
| 
Month | 
Formatting | 
>= 4 | 
interpreted as Text (full month
  name) | 
| 
Number | 
Formatting | 
minimum number of required digits | 
shorter numbers are padded with
  zeros | 
| 
Number | 
Parsing | 
number of pattern letters is
  ignored (unless needed to separate two adjacent fields) | 
any form | 
| 
General time zone | 
Both | 
1-3 | 
short or abbreviated form, if has
  a name. Otherwise, GMT offset value (GMT[sign][[0]0-23]:[00-59]) | 
| 
General time zone | 
Both | 
>= 4 | 
full form, , if has a name.
  Otherwise, GMT offset value (GMT[sign][[0]0-23]:[00-59]) | 
| 
General time zone | 
Parsing | 
>= 1 | 
RFC 822 time zone form is allowed | 
| 
RFC 822 time zone | 
Both | 
>= 1 | 
RFC 822 4-digit time zone format
  is used ([sign][0-23][00-59]) | 
| 
RFC 822 time zone | 
Parsing | 
>= 1 | 
General time zone form is allowed | 
Examples:
1.3 Date and Time Format Patterns and Results (Java)
| 
Date and Time Pattern | 
Result | 
| 
"yyyy.MM.dd G 'at' HH:mm:ss
  z" | 
2001.07.04 AD at 12:08:56 PDT | 
| 
"EEE, MMM d, ''yy" | 
Wed, Jul 4, '01 | 
| 
"h:mm a" | 
12:08 PM | 
| 
"hh 'o''clock' a, zzzz" | 
12 o'clock PM, Pacific Daylight
  Time | 
| 
"K:mm a, z" | 
0:08 PM, PDT | 
| 
"yyyyy.MMMMM.dd GGG hh:mm
  aaa" | 
02001.July.04 AD 12:08 PM | 
| 
"EEE, d MMM yyyy HH:mm:ss
  Z" | 
Wed, 4 Jul 2001 12:08:56 -0700 | 
| 
"yyMMddHHmmssZ" | 
010704120856-0700 | 
| 
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" | 
2001-07-04T12:08:56.235-0700 | 
****************************
JODA:
****************************
2.1 Date Format Pattern Syntax (Joda)
| 
Symbol | 
Meaning | 
Presentation | 
Examples | 
| 
G | 
Era designator | 
Text | 
AD | 
| 
C | 
Century of era (>=0) | 
Number | 
20 | 
| 
Y | 
Year of era (>=0) | 
Year | 
1996 | 
| 
y | 
Year | 
Year | 
1996 | 
| 
x | 
Week of weekyear | 
Year | 
1996 | 
| 
M | 
Month of year | 
Month | 
July; Jul; 07 | 
| 
w | 
Week of year | 
Number | 
27 | 
| 
D | 
Day of year | 
Number | 
189 | 
| 
d | 
Day of month | 
Number | 
10 | 
| 
e | 
Day of week | 
Number | 
2 | 
| 
E | 
Day of week | 
Text | 
Tuesday; Tue | 
| 
a | 
Halfday of day | 
Text | 
PM | 
| 
H | 
Hour of day (0-23) | 
Number | 
0 | 
| 
k | 
Clockhour of day (1-24) | 
Number | 
24 | 
| 
K | 
Hour of halfday (0-11) | 
Number | 
0 | 
| 
h | 
Clockhour of halfday (1-12) | 
Number | 
12 | 
| 
m | 
Minute of hour | 
Number | 
30 | 
| 
s | 
Second of minute | 
Number | 
55 | 
| 
S | 
Fraction of second | 
Number | 
970 | 
| 
z | 
Time zone | 
Text | 
Pacific Standard Time; PST | 
| 
Z | 
Time zone offset/id | 
Zone | 
-0800; -08:00; America/Los_Angeles | 
| 
' | 
Escape for text/id | 
Delimiter | 
(none) | 
| 
'' | 
Single quote | 
Literal | 
' | 
We can see from above table, although actual format strings for Java and Joda are almost 100% compatible with each other, still there are differences. The 'F' in default java is not supported in Joda.
Basically, 'F' means 'Day of week in month', for example, '2013-11-8' is the second friday in Nov of 2013, so 'F' will get 2 as result. While 'E' means 'Day of week' only, with the same example, '2013-11-8', 'E' will get 5 as result, because it's Friday, the fifth day in the week.
The number of symbol letters you specify also determines the format. The following table summarizes these rules:
2.2 Rules for Date Format Usage (Joda)
| 
Presentation | 
Processing | 
Number of Pattern Letters | 
Form | 
| 
Text | 
Formatting | 
1 - 3 | 
short or abbreviated form, if one
  exists | 
| 
Text | 
Formatting | 
>= 4 | 
full form | 
| 
Text | 
Parsing | 
>= 1 | 
both forms | 
| 
Year | 
Formatting | 
2 | 
truncated to 2 digits | 
| 
Year | 
Formatting | 
1 or >= 3 | 
interpreted as Number. | 
| 
Year | 
Parsing | 
>= 1 | 
intepreted literally | 
| 
Month | 
Both | 
1-2 | 
interpreted as a Number | 
| 
Month | 
Parsing | 
>= 3 | 
interpreted as Text (using Roman
  numbers, abbreviated month name - if exists, or full month name) | 
| 
Month | 
Formatting | 
3 | 
interpreted as Text (using Roman
  numbers, or abbreviated month name - if exists) | 
| 
Month | 
Formatting | 
>= 4 | 
interpreted as Text (full month
  name) | 
| 
Number | 
Formatting | 
minimum number of required digits | 
shorter numbers are padded with
  zeros | 
| 
Number | 
Parsing | 
>= 1 | 
any form | 
| 
Zone name | 
Formatting | 
1-3 | 
short or abbreviated form | 
| 
Zone name | 
Formatting | 
>= 4 | 
full form | 
| 
Time zone offset/id | 
Formatting | 
1 | 
Offset without a colon between
  hours and minutes | 
| 
Time zone offset/id | 
Formatting | 
2 | 
Offset with a colon between hours
  and minutes | 
| 
Time zone offset/id | 
Formatting | 
>= 3 | 
Full textual form like this:
  "Continent/City" | 
| 
Time zone offset/id | 
Parsing | 
1 | 
Offset without a colon between
  hours and minutes | 
| 
Time zone offset/id | 
Parsing | 
2 | 
Offset with a colon between hours
  and minutes | 
For more details, the official docs are the best place to go.
Reference:
Micosoft: StandardDate and Time Format Strings
Subscribe to:
Comments (Atom)

