Stack overflow error when loading web app from Spring property resolver - spring-mvc

It looks like there is a recursive loop in my spring set up.
I've looked in the applicationContext.xml and springapp-servlet.xml files and don't see any repeats or circular dependencies. I'm not all that familiar with spring and don't really know where to start to debug this.
Is there a way I can find out what property is being resolved?
Here's my stack dump
2014-10-04 00:39:45,872 [localhost-startStop-1] ERROR ContextLoader : Context initialization failed
java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.naming.internal.VersionHelper12.getJndiProperties(VersionHelper12.java:89)
at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:138)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)
at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiLocatorDelegate.lookup(JndiLocatorDelegate.java:38)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:77)
at org.springframework.jndi.JndiLocatorDelegate.lookup(JndiLocatorDelegate.java:33)
at org.springframework.jndi.JndiPropertySource.getProperty(JndiPropertySource.java:82)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:73)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:427)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:131)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:128)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:73)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:176)
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:146)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:174)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:143)
at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:163)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:76)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:176)
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:146)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:174)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:143)
at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:163)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:76)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:176)
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:146)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:174)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:143)
at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:163)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:76)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:176)
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:146)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:174)
at org.springfra

that happens since you dont have the datasource property file in your classpath or the direct values in your xml definitions where you have defined datasource or session factory

Related

Compiled Jar keeps throwing: Uncaught exception in the SynchronizationContext

I have been trying to make a small application which first scans a HTML for data and then uploads it to my Firestore. I'm now essentially done with it and when starting it from within IntelliJ IDEA it works just fine. However as soon as I export it in to an artifact it starts throwing the following exception when trying to download/upload from/to Firestore!
I should mention that I'm coding in Koltin/JVM as it is way easier. Since there is no Kotlin Firebase-Admin version I'm just using the Java one which shouldn't be a problem since Kotlin compiles down to Java. If I'm wrong about that please correct me!
Nov 27, 2019 6:59:17 PM io.grpc.internal.ManagedChannelImpl$1 uncaughtException
SEVERE: [Channel<1>: (firestore.googleapis.com:443)] Uncaught exception in the SynchronizationContext. Panic!
java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.<init>(AutoConfiguredLoadBalancerFactory.java:97)
at io.grpc.internal.AutoConfiguredLoadBalancerFactory.newLoadBalancer(AutoConfiguredLoadBalancerFactory.java:67)
at io.grpc.internal.ManagedChannelImpl.exitIdleMode(ManagedChannelImpl.java:379)
at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider$1ExitIdleModeForTransport.run(ManagedChannelImpl.java:473)
at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:95)
at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider.get(ManagedChannelImpl.java:477)
at io.grpc.internal.ClientCallImpl.startInternal(ClientCallImpl.java:257)
at io.grpc.internal.ClientCallImpl.start(ClientCallImpl.java:190)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1.start(CensusTracingModule.java:394)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1.start(CensusStatsModule.java:695)
at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:32)
at com.google.api.gax.grpc.GrpcHeaderInterceptor$1.start(GrpcHeaderInterceptor.java:94)
at com.google.api.gax.grpc.GrpcDirectStreamController.startCommon(GrpcDirectStreamController.java:115)
at com.google.api.gax.grpc.GrpcDirectStreamController.start(GrpcDirectStreamController.java:101)
at com.google.api.gax.grpc.GrpcDirectServerStreamingCallable.call(GrpcDirectServerStreamingCallable.java:68)
at com.google.api.gax.grpc.GrpcServerStreamingRequestParamCallable.call(GrpcServerStreamingRequestParamCallable.java:61)
at com.google.api.gax.grpc.GrpcExceptionServerStreamingCallable.call(GrpcExceptionServerStreamingCallable.java:59)
at com.google.api.gax.rpc.WatchdogServerStreamingCallable.call(WatchdogServerStreamingCallable.java:69)
at com.google.api.gax.rpc.ServerStreamingCallable$1.call(ServerStreamingCallable.java:237)
at com.google.api.gax.rpc.ServerStreamingAttemptCallable.call(ServerStreamingAttemptCallable.java:230)
at com.google.api.gax.rpc.ServerStreamingAttemptCallable.start(ServerStreamingAttemptCallable.java:193)
at com.google.api.gax.rpc.RetryingServerStreamingCallable.call(RetryingServerStreamingCallable.java:87)
at com.google.api.gax.tracing.TracedServerStreamingCallable.call(TracedServerStreamingCallable.java:76)
at com.google.api.gax.rpc.ServerStreamingCallable$1.call(ServerStreamingCallable.java:237)
at com.google.api.gax.rpc.ServerStreamingCallable.serverStreamingCall(ServerStreamingCallable.java:166)
at com.google.api.gax.rpc.ServerStreamingCallable.serverStreamingCall(ServerStreamingCallable.java:178)
at com.google.cloud.firestore.FirestoreImpl.streamRequest(FirestoreImpl.java:474)
at com.google.cloud.firestore.FirestoreImpl.getAll(FirestoreImpl.java:243)
at com.google.cloud.firestore.FirestoreImpl.getAll(FirestoreImpl.java:253)
at com.google.cloud.firestore.FirestoreImpl.getAll(FirestoreImpl.java:143)
at com.google.cloud.firestore.DocumentReference.get(DocumentReference.java:354)
at FirebaseHandler.getLehrer(FirebaseHandler.kt:95)
at HtmReader.readFile(HtmReader.kt:12)
at MainView.theStuff(MainView.kt:61)
at MainView.onDock(MainView.kt:44)
at tornadofx.UIComponent.callOnDock$tornadofx(Component.kt:700)
at tornadofx.UIComponent$rootSceneWindowShowingPropertyChangeListener$1.changed(Component.kt:556)
at tornadofx.UIComponent$rootSceneWindowShowingPropertyChangeListener$1.changed(Component.kt:327)
at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72)
at javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:103)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
at javafx.stage.Window.setShowing(Window.java:922)
at javafx.stage.Window.show(Window.java:937)
at javafx.stage.Stage.show(Stage.java:259)
at tornadofx.App.start(App.kt:101)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
My code which (in this case) downloads stuff is as following:
fun getLehrer(): HashMap<String, Any> {
[...]
val out = HashMap<String, Any>()
try {
val future = firestore.collection("stuff").document("lehrer").get()
future.await()
if (future.isDone) {
[...]
}
} catch (ex: Exception) {
println(" ++ cant get lehrer liste")
}
[...]
}
The error occurs at this line:
val future = firestore.collection("stuff").document("lehrer").get()
I have been trying to fix this for days now and literally spend hours googeling and trying different things but nothing has worked for me so far!
I tried:
randomly adding a LoadBalancer since I wasn't able to find any viable docs
adding the loadbalancer to my META-INF/services
I also found something that seemed similar here (https://github.com/grpc/grpc-java/issues/5493) but it talks about a load of stuff I don't use and frankly don't understand
FYI: Weirdly my icon from my resource folder turns into a completely different one in the Jar. Don't ask me why. I couldn't find an answer to that as well, but it isn't such a big issue since I can just replace that in the jar.
Oh and also this is my first question so if I made any mistakes I'm sorry! I probably made some spelling errors as well which I apologize for.
Any help would be greatly appreciated!
Hey so after googling some more I found some an article listing code snipets from LoadBalancerRegistry (https://www.codota.com/code/java/classes/io.grpc.LoadBalancerRegistry) and I scrolled around in it and found this: PickFirstBalancerFactory.init()
So i decided to look for this Factory but couldn't find it, instead I found PickFirstLoadBalancerProvider(). Remembering from randomly going through the autocomplete that in order to register something to LoadBalancerRegistry one would need a Provider.
Long story short I set them both together and added the following to the init section of my class and it works fine now!
LoadBalancerRegistry.getDefaultRegistry().register(PickFirstLoadBalancerProvider())
Thought I should answer if anyone has the same issue!
FYI: The icon still changes to that weird one. I don't know why or how thats even possible but it works if I replace it in the .jar so I don't really care xD

Websphere - javax.servlet.UnavailableException: Servlet not a servlet class

I get this error message when trying to connect to our webservices.
Error 404: javax.servlet.UnavailableException: SRVE0201E: Servlet [...] not a servlet class.
However, the class mentioned inside the brackets is a servlet class:
#WebService(serviceName = "xxx", endpointInterface = "xxx")
What I read was that in Websphere the class loader should be configured to Parent last; this is what I did and then to get rid of all jar - files that use Servlet.jar - I think I did this, too, since the only files that I am using are these ones:
antisamy-1.4.3.jar
api-7.9.0.0.jar
avalon-framework-4.1.3.jar
batik-css-1.7.jar
batik-ext-1.7.jar
batik-util-1.7.jar
bsh-core-2.0b4.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.7.0.jar
commons-codec-1.2.jar
commons-collections-3.2.jar
commons-configuration-1.5.jar
commons-digester-1.8.jar
commons-fileupload-1.2.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
core-7.9.0.0.jar
dom4j-1.6.1.jar
esapi-2.0_rc11.jar
istack-commons-runtime-2.16.jar
jaxb-api-2.2.9.jar
jaxb-core-2.2.8-b01.jar
jaxb-impl-2.2-promoted-b65.jar
jaxen-1.1-beta-8.jar
jdom-1.0.jar
log4j-1.2.16.jar
log4j-api-2.7.jar
log4j-core-2.7.jar
logkit-1.0.1.jar
nekohtml-1.9.12.jar
serializer-2.7.2.jar
xalan-2.7.2.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
xml-apis-ext-1.3.04.jar
xom-1.1.jar
Maybe someone could give me a hint or knows that the problem can be?
Thank you very much!
If you're relying on the annotation you mentioned, that's going to create a web service, not a servlet. Unless of course the class the #WebService is defined in extends javax.servlet.Servlet. Did you mean #WebServlet instead? Posting the pertinent portion of your source would be helpful.
This is one possibility:
https://developer.ibm.com/answers/questions/171243/srve0201e-servlet-my-webservice-not-a-servlet-clas.html
This text in particular:
The issue was showing up at deploy time and had to do with the fact
that my web services was referencing classes in a shared library. The
deploy code doesn't have access to the shared library so it wasn't
able to resolve things and gave up.
After some mad refactoring it started working.

Optaplanner as jar does not seem to read xml file

I am new to optaplanner
i worked in iDE and created a working prototype and now want to run in a prod mimic testing.
i created a jar of my entire project
but when i invoke the jar with the input files,
i get exception as "Null POinter Exception"
I tried created SolverFactory by two ways
Trial 1:
SolverFactory<PocSolution> factory = SolverFactory.createFromXmlResource(SOLVER_CONFIG,this.getClass().getClassLoader());
Trial 2:
SolverFactory<PocSolution> factory = SolverFactory.createFromXmlReader(new FileReader(SOLVER_CONFIG),this.getClass().getClassLoader());
Exception in thread "main" java.lang.NullPointerException
at org.kie.internal.io.ResourceFactory.newByteArrayResource(ResourceFactory.java:66)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.getResource(AbstractKieModule.java:299)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:264)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:259)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:228)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:74)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:251)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:219)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:177)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:503)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
at org.optaplanner.examples.MyPoc.app.Poc.solve(Poc.java:132)
at org.optaplanner.examples.MyPoc.app.Poc.main(Poc.java:41)
Your solver config file is being read successfully. The problem seems to be inside the <scoreDirectorFactory> element, where you specify score DRL. Please make sure that you use the <scoreDrl> element and not <scoreDrlFile>. <scoreDrlFile> is supposed to contain a local file system path whereas <scoreDrl> is used to load a classpath resource (which is the case when the DRL file is located inside a JAR). It should look similar to:
<scoreDirectorFactory>
<scoreDrl>org/myproj/core/solver/myRules.drl</scoreDrl>
</scoreDirectorFactory>

Jetty ConcatServlet to handle filter generated content

I try to use jetty's ConcatServlet to concatenate javascript generated from my own servlet and javascript generated by wro4j WroFilter. It seems concatenation doesn't work, regardless the javadoc of ConcatServlet that states that it can be used to concat generated content.
I think the issue is that the wro4j content is generated by a filter an not a servlet as 'concatenating' a single source generated by my servlet works fine, while 'concatenating' the single wro4j generated resource doesn't work but I get the exception below. It complaints about a missing file, although the request /wro/script.js is served fine if requested normally. Any suggestions?
java.io.FileNotFoundException: !/wro/script.js
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:465)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:526)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:586)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1105)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1039)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.Dispatcher.include(Dispatcher.java:169)
at org.eclipse.jetty.servlets.ConcatServlet.doGet(ConcatServlet.java:122)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:695)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1564)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:164)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1535)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:524)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1105)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1039)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:201)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:277)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:216)
at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)

Compiler Error Message: CS0103: The name 'Database' does not exist in the current context [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Razor-based view doesn't see referenced assemblies
I am a Newbie in ASP.net
I am trying to connect to a database and I keep getting this error
**Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Database' does not exist in
the current context
Source Error:
Line 1: #{
Line 2: var db = Database.Open("demo"); '
Line 3:
Line 4:
Source File: c:\Users\Ayoya\Documents\My Web Sites\demo\Page.cshtml
Line: 2
**
Can anyone tell me whats wrong?
Thank you
The compiler's already telling you what's wrong - it doesn't know what you mean by Database. Is that mean to be a property of the page, or is it the name of a type with a static Open method? It's not clear from the code itself, and obviously the compiler can't find the name either.
Work out what name you mean, then work out why the compiler can't see it, then fix that. If you need more help on any of these steps, you'll need to provide more information.
(As an aside, I completely agree with dbaseman: putting database calls in your view is a bad idea.)
If you're opening a database in your Razor view, that is completely the wrong approach. Your logic should go in the Controller, not the View. Consider creating a "view model" class that contains all the data needed for your view, and populate that class from the Controller.
Probably the reason this piece of code isn't working is that you will need to specify the full namespace of Database. I'm not sure what that class is, though; if it's in a separate DLL, you'll have more problems. Again, though, you should circumvent this problem by putting your database logic in the controller.

Resources