I'm trying to add new keys in application.conf file in play framework 2.1. I have added the following keys:
gen.db.host=localhost
gen.db.port=27017
gen.db.name=test
When i start my application, it is throwing the following error:
Configuration error: Configuration error[application.conf: 46: port has type NUMBER rather than OBJECT]
......
......
......
Caused by: com.typesafe.config.ConfigException$WrongType: application.conf: 46: port has type NUMBER rather than OBJECT
I don't understand this issue. How can i resolve it? Also, is it a good practice to define new keys in application.conf file?
Thanks.
Put the port between double quotes:
gen.db.port="27017"
You have to use a colon
gen.dn.port:"26017"
Here's a link to the current documentation
http://www.playframework.com/documentation/2.0.x/Configuration
You are propably using wrong method to extract the data from config. I assume you use it like:
current.configuration.getConfig("gen.db.port")
But this method returns play.api.Configuration and expects an object to be under the path "gen.db.port" (as it is mentioned in the error). Since under the "gen.db.port" path you have a number, you should change the method to:
current.configuration.getNumber("gen.db.port")
Related
In Log4j2's JsonTemplateLayout, I have no problem using eventTemplateUri: "classpath:LayoutTemplate.jsson" with json file located in rc/main/resources.
However, I would need to keep this file outside of class path. so I would like to use file location something like he way we add log fileName: c:\...
But it's throwing an error when I use eventTemplateUri: "C:\ ....\LayoutTemplate.json"
rror message is " Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLa
yout for element JsonTemplateLayout: java.lang.RuntimeException: failed reading URI: C:...
Did I miss anything here?
is it possible to place this json file outside of class path?
Thanks!
All *Uri configuration knobs in JsonTemplateLayout expect a URI string. In your case, the URI scheme is missing. The eventTemplateUri should look like file:///C:/path/to/LayoutTemplate.json in your case. For internals, see how o.a.l.l.l.template.json.util.Uris.readUri(String,Charset) is implemented.
I can't get this snippet running:
TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
rollingPolicy.setFileNamePattern("%d{yyyy-MM-dd}.log");
rollingPolicy.start();
Whatever pattern I try, I keep getting
Caused by: java.lang.IllegalStateException: FileNamePattern [%d{yyyy-MM-dd}.log] does not contain a valid DateToken
at ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicyBase.start(TimeBasedFileNamingAndTriggeringPolicyBase.java:46)
at ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy.start(DefaultTimeBasedFileNamingAndTriggeringPolicy.java:32)
at ch.qos.logback.core.rolling.TimeBasedRollingPolicy.start(TimeBasedRollingPolicy.java:90)
I've tried various examples from the docs, but what works in logback.xml doesn't seem to work in code.
According to this: https://github.com/tony19/logback-android/issues/51 you need a context and an appender. There is an example there.
I have two property files:
#environment.properties
env = production
and second file is:
#commons.properties
production.port = 123
test.port = 567
Also,I have resource file which need be filtered by environment.properties file and commons.properties file and copied.
The resource-file contains:
${${env}.port}
So,I want to filter my resource file with first file and get:
${production.port}
and then I want to filter it with second filter file and get:
123
I use maven 3.2.5 and the resource-file isn't filtered at all.
I know that there's issue related with this problem:
https://jira.codehaus.org/browse/MRESOURCES-70 But it still unresolved.
So,my question is - is there any solution to resolve this problem? (actually,I think that resource-plugin should be modified for work with nested property filtering).
And second question - does exist any way to avoid this problem by refactoring,I mean any other architecture solution. Or, what would you do if you had same problem?
I am getting this strange error while executing the following code.
EncoderRequest encoderRequest = new EncoderRequest(sid,appTxnId,pfid,transactionType,"",isUpdatetype9,true);
I have checked all the parameter values are valid. I am using java7 plateform.
can any one have come across this situation, please help.
following is the part of stacktrace i am getting.
Caused by: java.lang.ClassFormatError: Illegal local variable table length 48 in method com.cmc.facts.encoder.EncoderRequest.<init>(JLjava/lang/String;Ljava/lang/Long;Lcom/cmc/facts/enums/TransactionType;Ljava/lang/String;ZZ)V at com.cmc.facts.nist.NistReaderModel.preprossingOfNistFile(NistReaderModel.java:180) at com.cmc.facts.action.interstate.InterStateAction.uploadFIIF(InterStateAction.java:645) ... 115 more
There have been previous reports of the same error, on Junit tests and similar..
For them, adding the JVM arg -XX:-UseSplitVerifier seemed to work
Have a look at this article
You can also do this config :
Add -noverify in your jvg args
For ant config you can do : <jvmarg value="-noverify"/>
You can follow the link for more details on why we need to do this.
I have the following class which is persisted into a mongodb using morphia in a play! application. The class resides in a module which is a dependency of another play! application.
Its configuration is read from a file and persisted into the db on initial load (if its not already in the db) and then subsequent requests use the db version.
#Entity
public class Page extends Model {
#Id
public Long navigationId;
// etc ...
}
The initial load and subsequent query access works ok and i can see the page in mongo:
> db.Page.find({_id:20000})
{ "_id" : NumberLong(20000), "className" : "models.Page" etc }
However if i restart play! or make a code change that results in Morphia being reinitialised
(MorphiaPlugin-1.2.4> initialized appears in the logs) i get the following stack trace:
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:487)
at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
at com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:66)
at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53)
at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48)
at com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:255)
at play.modules.morphia.Model$MorphiaQuery.asList(Model.java:1067)
at models.Page.findAll(Page.java)
at plugins.PageConfigLoadPlugin.loadPersistedPages(PageConfigLoadPlugin.java:62)
at plugins.PageConfigLoadPlugin.onApplicationStart(PageConfigLoadPlugin.java:51)
at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
at play.Play.start(Play.java:495)
... 3 more
Caused by: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:27)
at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:501)
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
... 14 more
Caused by: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
at com.google.code.morphia.converters.DefaultConverters.fromDBObject(DefaultConverters.java:133)
at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:25)
... 16 more
If i drop the Collection from mongodb using the command line i can again load and query the Page obejct successfully from my play! web application
> db.Page.drop()
true
As I mentioned, this class is in a module. This problem only happens in one application that the module is a dependency of. The other demo application works fine.
any suggestions?
Does the dependent module have another alternate declaration of the Page or
Model classes?
From the top of the stack trace, ("com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000"), it looks like there's a type mismatch between
the way a numeric value is being stored and retrieved. For example, in Java,
it is not uncommon to store something as a Double and then mistakenly try
to retrieve it as an Integer or a Long. So, can you verify that the
declaration of navigationId in the dependent module is the same as the one
you've shown here? They should share the definition, but its possible there's
an alternate.
Another thing to check is that your code is putting a Long into your
DBObject and not a float. For example, if you're inserting it via the shell,
you'll need to use one of the wrappers, e.g.
db.Page.save({_id:NumberLong(20000)});
Otherwise, this will also cause a mismatch when you retrieve it; by default
numbers in JavaScript are doubles.