Coder Social home page Coder Social logo

Comments (7)

gregturn avatar gregturn commented on August 16, 2024 2

Looking at your example, your usage of @Controller makes this a view-based controller, expecting a template named greeting.html.

Why are you extending SpringBootServletInitializer? That's only needed for certain older configurations.

from gs-spring-boot.

gregturn avatar gregturn commented on August 16, 2024

Problem resolved?

from gs-spring-boot.

7-- avatar 7-- commented on August 16, 2024

No :-( I'm trying to do the same thing in the greeting example in my project. The repo is private so I don't know how much you can help. The logs look like it's working but when I try to this the service at http://localhost:8080/myservice/greeting or http://localhost:8080/greeting I get 404

Output:

com.example.main.Application             : Starting Application on DWC7DEVUS00046 with PID 13208 (C:\apache-tomcat-7.0.75\wtpwebapps\myservice\WEB-INF\classes started by me in \\dwshome-c.myoffice.example.com\dwsuserdata$\me\Desktop)
com.example.main.Application             : No active profile set, falling back to default profiles: default
ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7b0cc18b: startup date [Thu Oct 19 12:33:09 CDT 2017]; root of context hierarchy
o.a.c.c.C.[.[.[/myservice]               : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1315 ms
o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'errorPageFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7b0cc18b: startup date [Thu Oct 19 12:33:09 CDT 2017]; root of context hierarchy
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting]}" onto public java.lang.String com.example.pak1.GreetingController.greeting(java.lang.String,org.springframework.ui.Model)
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
oConfiguration$WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
com.example.main.Application             : Started Application in 4.919 seconds (JVM running for 12.035)
o.a.c.util.SessionIdGeneratorBase        : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [107] milliseconds.
org.apache.catalina.startup.HostConfig   : Deploying web application directory C:\apache-tomcat-7.0.75\webapps\docs
org.apache.catalina.startup.HostConfig   : Deployment of web application directory C:\apache-tomcat-7.0.75\webapps\docs has finished in 65 ms
org.apache.catalina.startup.HostConfig   : Deploying web application directory C:\apache-tomcat-7.0.75\webapps\examples
o.a.c.c.C.[.[localhost].[/examples]      : ContextListener: contextInitialized()
o.a.c.c.C.[.[localhost].[/examples]      : SessionListener: contextInitialized()
o.a.c.c.C.[.[localhost].[/examples]      : ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@27ead951')
org.apache.catalina.startup.HostConfig   : Deployment of web application directory C:\apache-tomcat-7.0.75\webapps\examples has finished in 490 ms
org.apache.catalina.startup.HostConfig   : Deploying web application directory C:\apache-tomcat-7.0.75\webapps\host-manager
org.apache.catalina.startup.HostConfig   : Deployment of web application directory C:\apache-tomcat-7.0.75\webapps\host-manager has finished in 69 ms
org.apache.catalina.startup.HostConfig   : Deploying web application directory C:\apache-tomcat-7.0.75\webapps\manager
org.apache.catalina.startup.HostConfig   : Deployment of web application directory C:\apache-tomcat-7.0.75\webapps\manager has finished in 69 ms
org.apache.catalina.startup.HostConfig   : Deploying web application directory C:\apache-tomcat-7.0.75\webapps\ROOT
org.apache.catalina.startup.HostConfig   : Deployment of web application directory C:\apache-tomcat-7.0.75\webapps\ROOT has finished in 54 ms
org.apache.coyote.http11.Http11Protocol  : Starting ProtocolHandler ["http-bio-8080"]
org.apache.coyote.ajp.AjpProtocol        : Starting ProtocolHandler ["ajp-bio-8009"]
org.apache.catalina.startup.Catalina     : Server startup in 12639 ms
package com.example.pak1;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {

    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}
package com.example.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"com.example.pak1"})
public class Application extends SpringBootServletInitializer {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

from gs-spring-boot.

7-- avatar 7-- commented on August 16, 2024

I have the greeting.html in src/main/resources/templates/greeting.html.

I was reading something and added SpringBootServletInitializer. I'm noticing without it, it doesn't say spring is detected, like I don't see the sping logo in the console. Also noticed with or without SpringBootServletInitializer I can run it as a java app and hit /greeting, but not the non spring servlets. When I run it as Tomcat I can't hit /greeting but can hit my non sping servlets.

from gs-spring-boot.

gregturn avatar gregturn commented on August 16, 2024

What's in your build file?

from gs-spring-boot.

7-- avatar 7-- commented on August 16, 2024
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.example.myservice</groupId>
	<artifactId>myservice</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.7.RELEASE</version>
	</parent>
	<build>
		<plugins>
			<plugin>
				<!-- Find servlet 3.0 version. I think this is changing it to 3.1 -->
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<warSourceDirectory>WebContent</warSourceDirectory>
					<failOnMissingWebXml>false</failOnMissingWebXml>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<includes>
						<include>**/JunitTestSuite.class</include>
					</includes>
					<!-- Used to debug container -->
					<!--<argLine>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000</argLine> -->
					<systemProperties>
					</systemProperties>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<properties>
		<strati-af-boms.version>3.2.1</strati-af-boms.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<start-class>hello.Application</start-class>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-all</artifactId>
			<version>1.9.5</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.5</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.0.1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.ws.rs</groupId>
			<artifactId>javax.ws.rs-api</artifactId>
			<version>2.0.1</version>
		</dependency>
		<dependency>
			<groupId>com.ibm.informix</groupId>
			<artifactId>jdbc</artifactId>
			<version>4.10.6.20151104</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.squareup.okhttp3</groupId>
			<artifactId>okhttp</artifactId>
			<version>3.7.0</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>spring-milestone</id>
			<url>http://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>spring-milestone</id>
			<url>http://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
</project>

from gs-spring-boot.

gregturn avatar gregturn commented on August 16, 2024

First of all, are you trying to build a WAR file? If not, then you can drop the customizations to spring-boot-maven-plugin, the maven-compiler-plugin, and replace spring-boot-starter-tomcat with spring-boot-starter-web. No need for the Java servlet API JAR either. By default, this version of Boot runs on servlet 3.1, which is modern day Tomcat.

Second of all, what I'm seeing veers way off course of what this is aimed at, so solving it without a proper code base to work against isn't really well suited in a ticket tracker used to manage changes to this guide. I wonder if you would be better served posting your use case on stackoverflow, because I feel as if something in missing the problem declaration.

from gs-spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.