Spring-boot configuration

I am trying to use a yeoman angular generator inside a Spring-boot application. I have the following project structure

/project -/src/main -- /java -- / resources --- /application.properties --- /public ---- /app ----- /index.html ----- /bower-components ----- /scripts ----- /views/**.html ----- /images ----- /styles

My goal is when the application loads up, index.html page would load from /project/src/main/resources/public/app/index.html and the URL should be "localhost:8080/#/". Currently, the URL looks like this localhost:8080/app/index.html.

I tried to put the mapping in application.properties as :

server.context-path=/public/app

I also tried to overwrite the Application configuration by extending WebMvcConfigurerAdapter. The class is :

@Configuration public class ApplicationConfiguration extends WebMvcConfigurerAdapter { private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/public/" }; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations( CLASSPATH_RESOURCE_LOCATIONS); } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController( "/" ).setViewName( "app/index" ); } }

But looks like this isn't working either. Can anyone comment on what am I missing and how to achieve the URL as "locahost:8080/#/" even if the index.html is located at /src/main/resources/public/app.

Note: If I keep my index.html page at /src/main/resources/public, the URL is shown as desired [locahost:8080/#/] . Any help is appreciated.

Thanks

-------------Problems Reply------------

Personally, I'm not sure if it is correct to access to your application's index page via localhost:8080/#/. As '#' is used to navigation on current page. Take a look at enter link description here answer about hyperlinks.

Edited:

Looks like your problem in CLASSPATH_RESOURCE_LOCATIONS. Have you tried to change "classpath:/resources/" to "classpath:/resources/app/"?

Otherwise, you can move your html files from resources folder to WEB-INF and add the configuration of InternalResourceViewResolver to your @ApplicationConfiguration class, set it as following:

@Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/app/");
resolver.setSuffix(".html");
return resolver;
}

I hope this helps.

In my application configuration, I added the app folder

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/public/app/" };

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);

Then added the method addViewControllers as :

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html") ;
}

No change in my folder structure (as mentioned the question) was required.

Hope this helps others as well.

Category:java Views:1 Time:2019-01-07

Related post

  • Spring boot JNDI datasource lookup failure - Name comp/env/jdbc not found in context "java:" 2014-12-15

    I have setup a spring boot (v 1.1.9) application to deploy as a WAR file. And I'm trying to integrate this web application with an existing data service module (added as a maven dependency). Environment trying to deploy: WebSphere Application Server

  • Configure Spring Boot + tomcat 8 to run on a non priviledged port 2014-05-09

    I am have a working spring boot + tomcat8 embedded application that bind to ports 8080 (http) and 8888 (https). Now I am looking for a way to configure the application to run a) on a privileged port i.e. port that is lower then 1024 i.e. port 80 and

  • How to use Spring Boot externalized configuration at Cloud Foundry 2015-01-29

    For externalizing configuration in a spring Boot application, I follow the standard way of having an application.properties in the classpath. And then, in the production environment, I put another application.properties beside the JAR which overrides

  • Spring Boot create a list of managed prototype beans from database configuration 2015-02-25

    I'm currently developing a Spring server application using Spring Boot. I need to develop a system where some InputStream will be sent from either the local File System, or from FTP, or some other source to specific InputStreamConsumer instances, all

  • Spring boot sitemesh filter Cannot Load excludes configuration file as specified in sitemesh.xml 2014-12-11

    In a spring boot application I am writing I have sitemesh set up as follows: @Bean public FilterRegistrationBean sitemeshFilter(){ FilterRegistrationBean filter = new FilterRegistrationBean(); filter.setName("sitemesh"); filter.setFilter(new SiteMesh

  • Why does Spring's @Configurable sometimes work and sometimes not? 2009-05-06

    I'm trying to use automatic dependency injection via Spring's @Configurable annotation w/ @Resource on the fields needing injection. This involved some setup, like passing spring-agent.jar to my JVM. For the full details see here. It works... mostly.

  • Why doesn't AspectJ compile-time weaving of Spring's @Configurable work? 2009-05-23

    Update 5: I've downloaded the latest Spring ToolsSuite IDE based on the latest Eclipse. When I import my project as a Maven project, Eclipse/STS appears to use the Maven goals for building my project. This means AspectJ finally works correctly in Ecl

  • Tomcat Not reading Spring-Boot Application Properties 2013-12-18

    I'm fairly new to spring/java and have been checking out spring-boot for a project I have at work. I've been following guides and finally have a (semi) working web app MVC + JPA for data access. Everything works when I deploy the app via the Jar meth

  • Spring Boot on Heroku Integration.xml not found 2014-01-30

    I am attempting to deploy a Spring Boot app on Heroku following this guide: http://codingricky.com/booting-spring-boot-into-heroku/ (thanks Ricky Yim) It seems pretty straight forward, but my app includes an integration.xml as required by the spring-

  • How do I delay evaluation of a Spring @Conditional configuration annotation? 2014-05-07

    I have a Spring @Configuration class that should register a bean when a specific property value is set in the environment. I wrote a custom Condition implementation that checked whether the value was present, and it works when I fire up the applicati

  • Spring Boot start fails for Autoconfigure on RabbitMQ 2014-06-11

    I have a large Spring boot application with uses amongst other thing RabbitMQ. I created a @Configuration file for the Rabbit queues. This has been working fine on Spring boot 1.0.2. Today I upgraded version 1.1.0 and now I am getting an exception on

  • Specify main class Spring-Boot command line 2014-06-20

    I use maven plugin to set the main class like this : <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.myapp.main.MainClass

  • How to create JNDI context in Spring Boot with Embedded Tomcat Container 2014-07-24

    import org.apache.catalina.Context; import org.apache.catalina.deploy.ContextResource; import org.apache.catalina.startup.Tomcat; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApp

  • Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path with maven and spring boot 2014-09-09

    I don't know how do I solve this issue. Please take a look and if possible let me how do I solve it. Here is my pom.xml file. <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</arti

  • Spring Boot Websockets in Wildfly 2014-09-11

    Hi I need to deploy my Spring Boot app into Wildfly 8.1 and I'm getting the following exception: Caused by: java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.w

  • Can I enable the tomcat manager app for Spring Boot's embedded tomcat? 2014-09-23

    I'm doing a research project to determine to what extent we can configure embedded Tomcat with Spring boot. One of the items I was asked to look into was with regard to whether we can still use the app manager. I don't have a specific use case for wh

  • Changing default welcome-page for spring-boot application deployed as a war 2014-09-26

    I was trying to find a way to change the default welcome-page for a spring-boot application that is being deployed as a war in production but I can't find a way to do it without a web.xml file. According to the documentation we can do it using the Em

  • Spring Boot: Log all incoming HTTP requests when using an embedded Jetty server? 2014-09-26

    I'm building a web app using Spring Boot 1.1.5.RELEASE and I've configured an embedded Jetty as described in the related Spring Boot's documentation. I want to log all incoming HTTP requests and the only solution I can think (after reading "how to co

  • Spring boot health endpoint for SOLR 2014-09-30

    I using Spring boot embedded tomcat and SOLR for dummy example. In my configuration class I have used @Bean public CloudSolrServer solrServer(){ return new CloudSolrServer(zkEnsemble); } While hitting the health URL below is the message am getting. {

  • How do you get a transaction manager in a non web Spring Boot Appllication? 2014-10-26

    Is there a quick and easy way to get a ComamandLineRunner app to have a transaction manager? I have the following setup: @EnableAutoConfiguration(exclude={WebMvcAutoConfiguration.class}) and spring.main.web_environment=false in the application.proper

  • Monitoring JMX end points of Spring boot CLI application with jolokia 2014-11-13

    I have a CLI micro service which has exposed endpoints @Configuration @EnableAutoConfiguration @EnableConfigurationProperties @ComponentScan public class TestLauncher implements CommandLineRunner { ... } pom <dependencyManagement> <dependenc

  • Speed up Spring Boot startup tim 2014-12-01

    I have a Spring Boot application. I've added a lot of dependencies (unfortunately, looks I need all of them) and the startup time went up quite a lot. Just doing a SpringApplication.run(source, args) takes 10 seconds. While that might not be much com

  • making services as POJO w/o spring dependencies in spring boot 2014-12-15

    I have a multi module maven project with the following structure -commons -validation -transformation commons module has got classes that does bulk of the work. While in validation and transformation I have two services that I want to expose it over

  • Spring Boot Multiple Datasource 2014-12-23

    I'm quite new to spring boot and I'd like to create a multiple datasource for my project. Here is my current case. I have two packages for entity for multiple database. Let's say com.test.entity.db.mysql ; for entities that belong to MySql com.test.e

  • Testing Spring Boot MVC with autowired repositories 2015-01-21

    I have two projects. One called myCore and one called myWeb. myCorecontains all of the beans and repository interfaces. myWeb is simply a JSON api that brings in myCore as a dependency. When I run myWeb everything works fine. When I try to run unit t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.126 (s). 11 q(s)