I don't know why you are having trouble with the sample, I just tested it and it worked ok.
However, probably the simplest way to get started with STS is (using a recent version >= 3.7)...
- File | New... | Spring Starter Project
- Set the name to, e.g.
rest
- Click next
- Select
Web, Integration (under IO)
- Click Finish
- Open
demo.RestApplication (where Rest is capitalized name from #2)
- Add
@ImportResource("classpath:context.xml")
- Create
context.xml in src/main/resources
- Run the application and hit
http://localhost:8080/foo/bar in your browser - it will output BAR.
RestApplication:
@SpringBootApplication
@ImportResource("classpath:context.xml")
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
}
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<int-http:inbound-gateway request-channel="in"
path="/foo/{id}"
supported-methods="GET"
request-payload-type="java.lang.String">
<int-http:header name="requestedId" expression="#pathVariables.id" />
</int-http:inbound-gateway>
<int:transformer input-channel="in" expression="headers['requestedId'].toUpperCase()" />
</beans>
EDIT
To make a deployable war, follow the Spring Boot instructions 'Create a deployable war' here.
But see the note about old servlet containers that don't support servlet 3.x.
Here's the updated RestApplication class...
@SpringBootApplication
@ImportResource("classpath:context.xml")
public class RestApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RestApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
}