If we are calling an internal service we would look up its address from a service registry. But what if the service we are calling is external like some google api. What is the right place to declare the url? In the .net world we would define it in web.config but not sure what would be a good place to declare it in spring mvc.
If you are using Spring Framework
Good place to define all your static URLs would be in *.properties file.
Default one is application.properties
This file will be added in src/main/resources folder of project
Related
In Quarkus, We have properties file inside project itself called application.properties.
Is there any Quarkus way to define external properties file in my use case like i am developing a mail sender and i want to add recipients in future.
Is it possible to give application.properties outside at local and inject it at runtime?
You can add a configuration file in your application working directory under config/application.properties : https://quarkus.io/guides/config#overriding-properties-at-runtime
There is ongoing discussion to have more runtime configuration capabilities here: https://github.com/quarkusio/quarkus/issues/1218
You can achieve this by keeping .properties (or .yaml) in Spring Cloud Config Server.
It's really easy to set it up. It's is well documented in following link (official documentation):
Quarkus - Reading properties from Spring Cloud Config Server
As loïc says, you can follow the convention and create a config/application.properties. You can also use the property quarkus.config.locations to specify additional config locations. It can be defined at runtime like below
java -Dquarkus.config.locations=app-config/config.properties -jar my-app.jar
I would like to ask where is the location where you can see the work directory of a spring boot / spring mvc applicaiton. Specifically I want to know Transpiled JSP files converted to java files.
I can see the class files inside the target directory, but cannot find the transpiled jsp files. Is there a class call where I can see it in my environment? Like System.getProperty("user.dir") or new java.io.File(".").getCanonicalPath(). I tried both and it only showed me the code path.
Also, I know the Eclipse Server path. But in spring boot, it does not seem to run using a server instance of tomcat. So the following path is not existing?
The following directory is also blank.
projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/
The base dir is set via the property server.tomcat.basedir, see: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html
The work dir is derrived from there by appending /work.
Spring HATEOAS works great at linking to another method in the same application. For example:
Greeting greeting = new Greeting(String.format(TEMPLATE, name));
greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel());
If one were to implement a microservice architecture, then most of the linked methods would be part of a different service and different Java project.
The only way I can see of to add a link to a method outside of the existing project is to hard-code in the URL (or put it in an external configuration).
Are there any alternatives to dynamically create the URL? For instance, is it possible to use Spring HATEOAS in conjunction with a Service Registry (like Eureka)?
I am developing a webapplication using asp.net mvc 3.
In the solution I have a project for all the web/presentation things (models, views, controller) and in another project I have my services, daos and domainobject. now I created a config-file in my service-project with some settings. how can I access the file from my services?
If I don't set a path it uses the path of the asp.net exe.
Hope someone can help
Tobi
You can use AppDomain.CurrentDomain.BaseDirectory to get proper path.
Or change Build action property of your config file to Embedded Resource (msdn). After that you will be able to retrieve file using ResourceManager
I'm developing a Spring application which needs to support pluggable modules - add the JAR to the classpath and it will automatically find and load the module's Spring application context XML. This part is already working.
The problem right now is figuring out a way for the modules to provide custom JSP pages. Each module will require a configuration page, which contains form fields specific to that module.
How can I use Spring MVC to implement such pluggable pages? It should work something like so, that the module's JAR file contains the configuration page (as JSP) and its Spring MVC controller, which the surrounding application will then include into the rest of the application (maybe as a JSP fragment inside the application's page template).
If this cannot be done with Spring MVC and JSP, then what would be a good alternative?
Try adding a ResourceBundleViewResolver config to each pluggable module (not sure if having multiple resolvers will work or not, but it allows you to define views via the classpath, not specific locations. See http://static.springsource.org/spring/docs/current/reference/view.html.
If having multiple resolvers in your modules don't work, then try ResourceBundleViewResolver in the main app config, and then have all pluggable modules follow the same view location setup internally to the JARs.