Reputation: 61
Hello i am trying to learn wildfly and springboot with a very simple application using eclipse. The project name is springboot-test. All the classes including the main method class are in the same package.
Main method class is called 'App' which has the following code:
@SpringBootApplication
@RestController
public class App {
@Autowired
private Student student;
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@RequestMapping("/index")
public String sayHello()
{
return "hello from spring boot" + this.student.showAddress();
}
}
Here are the server logs:
11:36:57,281 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) WFLYUT0021: Registered web context: '/springboot-test-0.0.1-SNAPSHOT' for server 'default-server'
11:36:57,301 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "springboot-test-0.0.1-SNAPSHOT.war" (runtime-name : "springboot-test-0.0.1-SNAPSHOT.war")
11:36:57,408 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
11:36:57,411 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:8181/management
11:36:57,412 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:8181
11:36:57,412 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 11.0.0.Final (WildFly Core 3.0.8.Final) started in 11393ms - Started 504 of 732 services (353 services are lazy, passive or on-demand)
Url i am accessing is: http://localhost:8080/springboot-test/index
Upvotes: 6
Views: 5239
Reputation: 664
Your Server log says:
11:36:57,281 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) WFLYUT0021: Registered web context: '/springboot-test-0.0.1-SNAPSHOT' for server 'default-server'
It should be accessible at: http://localhost:8080/springboot-test-0.0.1-SNAPSHOT/index
Configure your Maven file to use <finalName>${project.artifactId}</finalName>
if you like to register your address.
Upvotes: 0
Reputation: 8091
Since you are using wildfly for deployment , I'm hoping you are generating war file and server logs seems to support my statement
Do you have SpringBootServletInitializer class ??? if not that's the issue
You need something like this
@SpringBootApplication
@RestController
public class ServletInitializer extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(ServletInitializer.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServletInitializer.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException{
super.onStartup(servletContext);
}
@RequestMapping("/index")
public String sayHello(){
return "hello from spring boot" + this.student.showAddress();
}
}
I' not sure is there any issue in annotating @SpringBootApplication
and @RestController
in one class. But my suggestion is to keep it separate for maintenance
@RestController
public class Mycontroller{
@RequestMapping("/index")
public String sayHello(){
return "hello from spring boot" + this.student.showAddress();
}
}
Upvotes: 3