Rectangle 27 5

There's a sample app here that runs on GAE, currently deployed here: http://dsyerboot.appspot.com/.

I will have a look at the GAE sample later. I understand running on GAE implies that actuator might not be usable.

It would always be an add-on I think. It's definitely still a prototype at the minute, but I don't mind adding features and fixing bugs (pull requests, of course are welcome). Maybe we can have some more confidence that it works and covers all the bases if more people use it.

Btw would it work by using AnnotationConfigWebApplicationContext in web.xml and just adding @ EnableAutoConfiguration to the @ Configuation class defined via contextConfigLocation?

java - Does Spring Boot support servlet 2.5 auto-configuration? - Stac...

java spring google-app-engine spring-boot servlet-2.5
Rectangle 27 7

Spring-boot (or more generally spring) has nothing to do with the structure of your project in terms of maven modules. Creating the project structure is not part of what spring does.

Maven operates at build time, to compile and package the necessary artifacts (jars, wars...). Maven is the one who depends on the project structure.

Spring operates at runtime, once the applications is already built. The way the application was built does not matter to him.

Spring can access classes and resources form the application classpath. The application classpath can very well be composed of multiple artifacts, in the case of a multi-module project.

So yes, spring can work in a multi-module project, because it does not care for the structure of the project. It only cares that the necessary resources are available in the classpath once the application is running.

Nice explanation. However, spring-boot is not just about runtime, it's more like an ecosystem that unifies various aspects of enterprise java development, including the build process. spring-boot-starter-web is an example.

java - Does Spring Boot support multimodule maven projects? - Stack Ov...

java spring maven jpa spring-boot
Rectangle 27 53

There isn't a special annotation to denote a servlet filter. You just declare a @Bean of type Filter (or FilterRegistrationBean). An example (adding a custom header to all responses) is in Boot's own EndpointWebMvcAutoConfiguration;

If you only declare a Filter it will be applied to all requests. If you also add a FilterRegistrationBean you can additionally specify individual servlets and url patterns to apply.

FilterRegistrationBean
org.springframework.boot.context.embedded.FilterRegistrationBean
org.springframework.boot.web.servlet.FilterRegistrationBean

Would you mind to tell me how to include corresponding entry in build.gradle? I added the following, but it doesn't get compiled: providedCompile('javax.servlet:servlet-api:2.5') runtime('javax.servlet:jstl:1.1.2')

Spring Boot isn't going to work with Servlet 2.5, and there isn't really much support for JSP yet. I'm not really a gradler, so I don't know what you are trying to do. What's wrong with "compile"? Does it work if you just depend on "spring-boot-starter-web"? (I don't think these questions are related to the original question though, so maybe you should post again with the new questions?)

I added a filter by implementing Filter interface, however Eclipse is unable to find the interface. So I am trying to figure out how to add it to classpath for compiling.

Yes, of course you need to have Filter on your classpath. Normally I would just use the spring-boot-starter-web to pull in all the relevant depdendencies (e.g. here).

404 on the EndpointWebMvcAutoConfiguration link

java - How to add a filter class in Spring Boot? - Stack Overflow

java configuration spring-boot servlet-filters
Rectangle 27 53

There isn't a special annotation to denote a servlet filter. You just declare a @Bean of type Filter (or FilterRegistrationBean). An example (adding a custom header to all responses) is in Boot's own EndpointWebMvcAutoConfiguration;

If you only declare a Filter it will be applied to all requests. If you also add a FilterRegistrationBean you can additionally specify individual servlets and url patterns to apply.

FilterRegistrationBean
org.springframework.boot.context.embedded.FilterRegistrationBean
org.springframework.boot.web.servlet.FilterRegistrationBean

Would you mind to tell me how to include corresponding entry in build.gradle? I added the following, but it doesn't get compiled: providedCompile('javax.servlet:servlet-api:2.5') runtime('javax.servlet:jstl:1.1.2')

Spring Boot isn't going to work with Servlet 2.5, and there isn't really much support for JSP yet. I'm not really a gradler, so I don't know what you are trying to do. What's wrong with "compile"? Does it work if you just depend on "spring-boot-starter-web"? (I don't think these questions are related to the original question though, so maybe you should post again with the new questions?)

I added a filter by implementing Filter interface, however Eclipse is unable to find the interface. So I am trying to figure out how to add it to classpath for compiling.

Yes, of course you need to have Filter on your classpath. Normally I would just use the spring-boot-starter-web to pull in all the relevant depdendencies (e.g. here).

404 on the EndpointWebMvcAutoConfiguration link

java - How to add a filter class in Spring Boot? - Stack Overflow

java configuration spring-boot servlet-filters
Rectangle 27 12

You can specify port by overriding EmbeddedServletContainerFactory bean within your configuration (java based or xml). There you can specify port for used embedded servlet container. Please, see Spring Boot - Core "Embedded Servlet Container Support" paragraph and example there. Hope this helps.

java - Spring Boot - how to configure port - Stack Overflow

java spring tomcat spring-boot configuration
Rectangle 27 1

They're both the same thing, namely profile configuration. However, Spring boot does bring some additional features to Spring profiles like:

  • You can provide your application properties separately for each profile by using application-<profile name>.properties (or .yml) files. For example, if you create a file called application-test.properties and you run the application with this profile, Spring boot will load these configuration properties as well
  • Spring boot also has a configuration property called spring.profiles.active which allows you to configure which profile(s) should be used for the Spring boot application.

java - Does spring profiles and spring boot profiles is the same? - St...

java spring spring-boot spring-profiles
Rectangle 27 10

To add a Servlet, Filter, or Servlet *Listener provide a @Bean definition for it.

@Bean
public Filter compressFilter() {
    CompressingFilter compressFilter = new CompressingFilter();
    return compressFilter;
}
@Bean
@Configuration

Also you can add Servlets, Filters, and Listeners using classpath scanning,

@WebServlet, @WebFilter, and @WebListener annotated classes can be automatically registered with an embedded servlet container by annotating a @Configuration class with @ServletComponentScan and specifying the package(s) containing the components that you want to register. By default, @ServletComponentScan will scan from the package of the annotated class.

java - How to add a filter class in Spring Boot? - Stack Overflow

java configuration spring-boot servlet-filters
Rectangle 27 10

To add a Servlet, Filter, or Servlet *Listener provide a @Bean definition for it.

@Bean
public Filter compressFilter() {
    CompressingFilter compressFilter = new CompressingFilter();
    return compressFilter;
}
@Bean
@Configuration

Also you can add Servlets, Filters, and Listeners using classpath scanning,

@WebServlet, @WebFilter, and @WebListener annotated classes can be automatically registered with an embedded servlet container by annotating a @Configuration class with @ServletComponentScan and specifying the package(s) containing the components that you want to register. By default, @ServletComponentScan will scan from the package of the annotated class.

java - How to add a filter class in Spring Boot? - Stack Overflow

java configuration spring-boot servlet-filters
Rectangle 27 15

Now that I look closer, I think that the DataSource problem is a red-herring. Boot's Hibernate auto-configuration is being triggered and that's what causing a DataSource to be required. Hibernate's on the classpath because you've got a dependency on spring-boot-starter-data-jpa which pulls in hibernate-entitymanager.

spring-boot-starter-data-jpa
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Error still the same :-(

Are you sure you've applied the exclusion properly? mvn dependency:tree will help you to check. With the exclusion in place the DataSource problem's gone for me (I now see "Type demo.core.entity.Resource is not a known managed type", but that's a separate issue)

Hi Andy does it mean you tested the actual project I posted? looks promising

Yes, that was with the project you posted. The only change I made was to add the Hibernate exclusion as described above.

Cool, it seems what you've compiled was the master branch, or the JPA branch?

java - Spring Boot - Cannot determine embedded database driver class f...

java google-app-engine jpa spring-data spring-boot
Rectangle 27 6

I think that using the @EnableAutoConfiguration annotation on a test class won't work if you are using @SpringApplicationConfiguration to load your Application class. The thing is that you already have a @EnableAutoConfiguration annotation in the Application class that does not exclude the CrshAutoConfiguration.Spring uses that annotation instead of the one on your test class to do the auto configuration of your beans.

I think that your best bet is to use a different application context for your tests and exclude the CrshAutoConfiguration in that class.

@EnableAutoConfiguration
@SpringApplicationConfiguration
SpringJUnit4ClassRunner

How do you structure a project with several different applications? Won't Spring Boot scan the other Application(s) anyway? What's the recommended best practice for this scenario...? I think this is common usage, having test configuration somewhat different than application configuration.

java - How to exclude *AutoConfiguration classes in Spring Boot JUnit ...

java spring junit spring-boot
Rectangle 27 6

Turns out it does work. However, it seems you have to use configuration properties, since simple @Value("${prop}") seems to use a different path under the hood. (There are some hints to DataBinder in this secion. Not sure if related.)

application.properties
foo.bar[0]="a"
foo.bar[1]="b"
foo.bar[2]="c"
foo.bar[3]="d"

and in code

@Component
@ConfigurationProperties(prefix="foo")
public static class Config {
    private final List<String> bar = new ArrayList<String>();
    public List<String> getBar() {
        return bar;
    }
}

@Component
public static class Test1 {
    @Autowired public Test1(Config config) {
        System.out.println("######## @ConfigProps " + config.bar);
    }
}
######## @ConfigProps ["a", "b", "c", "d"]
@Component
public static class Test2 {
    @Autowired public Test2(@Value("${foo.bar}") List<String> bar) {
        System.out.println("######## @Value " + bar);
    }
}

results in

java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.bar' in string value "${foo.bar}"
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(...
    ...

java - Spring Boot - Populate List/Collection from Application.propert...

java spring spring-boot
Rectangle 27 10

The layout of the JAR has changed in Spring Boot 1.4.1

The layout of executable jars has changed in Spring Boot 1.4.1: applications dependencies are now packaged in BOOT-INF/lib rather than lib, and applications own classes are now packaged in BOOT-INF/classes rather than the root of the jar. And it affects Jersey:

The change to the layout of executable jars means that a limitation in Jerseys classpath scanning now affects executable jar files as well as executable war files. To work around the problem, classes that you wish to be scanned by Jersey should be packaged in a jar and included as a dependency in BOOT-INF/lib. The Spring Boot launcher should then be configured to unpack those jars on start up so that Jersey can scan their contents.

I've found that registering classes instead of packages works. See below the steps to create an application with Spring Boot and Jersey.

pom.xml
spring-boot-starter-parent
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
</parent>

You also need the following dependencies:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

And the Spring Boot Maven plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

For example purposes, create a Jersey resource class annotated with @Path and define a resource method to handle GET requests, producing text/plain:

@Path("/greetings")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Response getGreeting() {
        return Response.ok("Hello, World!").build();
    }
}

Then create a class that extends ResourceConfig or Application to register the Jersey resources and annotated it with @ApplicationPath. Registering classes instead of registering packages works with Spring Boot 1.4.1:

@Component
@ApplicationPath("api")
public class JerseyConfig extends ResourceConfig {

    @PostConstruct
    private void init() {
        registerClasses(GreetingResource.class);
    }
}

And finally create a Spring Boot class to execute the application:

@SpringBootApplication
public class Application {

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

If you want to test this web service, you can use the JAX-RS Client API:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class GreetingResourceTest {

    @LocalServerPort
    private int port;

    private URI uri;

    @Before
    public void setUp() throws Exception {
        this.uri = new URI("http://localhost:" + port);
    }

    @Test
    public void testGreeting() {

        Client client = ClientBuilder.newClient();
        Response response = client.target(uri).path("api").path("greetings")
                                  .request(MediaType.TEXT_PLAIN).get();

        String entity = response.readEntity(String.class);
        assertEquals("Hello, World!", entity);
    }
}

To compile and run the application, follow these steps:

  • Open a command line window or terminal.
  • Navigate to the root directory of the project, where the pom.xml resides.
mvn clean compile
  • Package the application: mvn package.
  • Look in the target directory. You should see a file with the following or a similar name: spring-jersey-1.0-SNAPSHOT.jar.
  • Change into the target directory.
java -jar spring-jersey-1.0-SNAPSHOT.jar
http://localhost:8080/api/greetings
ResourceConfig

Thanks Cassio for a comprehensive response. However, both of us appear to have followed same steps except for Maven dependency. I was using spring-boot-starter-jersey and you have used jersey-spring3. Can you try using the former as i am inclined to use that in my setup.

spring-boot-starter-jersey

java - JAX-RS does not work with Spring Boot 1.4.1 - Stack Overflow

java maven spring-boot jax-rs
Rectangle 27 3

Turns out it does work. However, it seems you have to use configuration properties, since simple @Value("${prop}") seems to use a different path under the hood. (There are some hints to DataBinder in this secion. Not sure if related.)

application.properties
foo.bar[0]="a"
foo.bar[1]="b"
foo.bar[2]="c"
foo.bar[3]="d"

and in code

@Component
@ConfigurationProperties(prefix="foo")
public static class Config {
    private final List<String> bar = new ArrayList<String>();
    public List<String> getBar() {
        return bar;
    }
}

@Component
public static class Test1 {
    @Autowired public Test1(Config config) {
        System.out.println("######## @ConfigProps " + config.bar);
    }
}
######## @ConfigProps ["a", "b", "c", "d"]
@Component
public static class Test2 {
    @Autowired public Test2(@Value("${foo.bar}") List<String> bar) {
        System.out.println("######## @Value " + bar);
    }
}

results in

java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.bar' in string value "${foo.bar}"
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(...
    ...

java - Spring Boot - Populate List/Collection from Application.propert...

java spring spring-boot
Rectangle 27 3

I finally found a viable solution. I post it, if it can help someone else.

The problem effectively came from Spring Security. I found this documentation from the Spring Security reference documentation that help me a bit.

Finally, the things I do to make my application running on a Tomcat 6 (Servlet 2.5) or Tomcat 7 (Servlet 3.0) were :

  • in pom.xml (again), keep the dependency to spring-boot-legacy
  • in pom.xml, replace the dependency to spring-boot-starter-security by the ones of Spring Security (spring-security-web and spring-security-config)
  • in web.xml, add the filter springSecurityFilterChain with filter class org.springframework.web.filter.DelegatingFilterProxy

These are my dependencies in pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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">
    ...
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
            <version>1.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        ...
    </dependencies>
    ...
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.acme.Application</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>ERROR</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

        @Inject
        private AuthenticationProvider authenticationProvider;

        @Inject
        protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(authenticationProvider);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .antMatcher("/api/**")
                .authorizeRequests().anyRequest()
                .fullyAuthenticated().and().httpBasic();
        }
}

This solution works well on Tomcat 6 but not on WebLogic 10.3.X :-/ I've found a blog post that proposes to use the Spring Boot application property "spring.main.sources" as : spring.main.sources=com.acme.Application To be tested...

were you able to deploy the app in WLS 10.3.6? I'm in the same boat, forced to deal with WLS 10.3.6 :(

I'm sorry but "no", we were not able to deploy on WLS 10.3.6... After a full week of lots of problems (web.xml, weblogic.xml, class loading order / dependencies) we had to give up and to convince the client to move on a more modern server. He finally accept to move on Tomcat 7 (yet it is an old insurance domain leader !). Sorry and good luck !

javax.servlet.ServletException: Filter execution threw an exception

java - Application does not start with Spring Boot 1.2.1 + Spring Secu...

java spring-security spring-boot servlet-2.5
Rectangle 27 2

Injecting into configuration classes might be a challenge, I wouldn't recommend it especially if that class is also an actual bean. IMHO your class does too much. Next to that move the configuration of the ThreadPoolTaskExecutor where it belongs.

Instead of autowiring create a @Bean method which returns a CommandLineRunner instead of you implementing it.

@SpringBootApplication
@EnableAsync
public class App {

    private static final Logger log = LoggerFactory.getLogger(App.class);

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

    @Bean
    public CommandLineRunner runner(AsyncClass async) {

      return new CommandLineRunner() {
        public void run(String... arg0) throws Exception {
            log.info("in run");
            async.start();
            log.info("done run");
        }      
      };

    }

    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {

        ThreadPoolTaskExecutor bean = new ThreadPoolTaskExecutor();
        bean.setCorePoolSize(1);
        bean.setMaxPoolSize(1);
        bean.setQueueCapacity(10);
        bean.setThreadPriority(1);
        bean.setWaitForTasksToCompleteOnShutdown(true);
        return bean;
    }
}

And of course cleanup your AsyncClass.

Thanks. This setup would work in the simple example with a thread that initiates at startup, however the full program contains one of these as well as a second task that gets called via a web request, so putting the ThreadPoolTaskExecutor beans in their own separate @Configuration classes was the simplest solution.

java - @Async not working after upgrading to Spring Boot 1.3.3 - Stack...

java spring asynchronous spring-boot
Rectangle 27 1

Spring Boot already configures Thymeleaf for you, so no need to configure that manually. Remove all Thymeleaf related configuration, also remove @EnableWebMvc as that interferes with the Spring Boot auto configuration. The @ComponentScan is also redundant.

Spring Boot also registered a MessageSource for you so no need to configure that. Not sure what the servlet registration is you do but that is the only thing you need.

Also I suggest to remove your controller and use a view controller which you can configure in your WebConfig class. Saves you a controller.

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter  {

    @Bean
    ServletRegistrationBean servletRegistration(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.addUrlMappings("/console/*");
        return registrationBean;
    }

    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }
}

To let the auto configured message source pickup your custom bundles add the following to src/main/resources/application.properties.

spring.messages.basename=/WEB-INF/i18/thymeleafResource
SpringThymeLeafApplication
SpringBootServletInitializer
@SpringBootApplication
public class SpringThymeLeafApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringThymeLeafApplication.class);
    }
}
src/main/resources/templates
src/main/resources/resources/templates

I have done all the thing you have mention. I have remove everything like webconfig.java and anything which is related to thymeleaf. there is only security configuration and boot configuration. I have also created error.html page in template. not error page showing instead controller page.

java - Unable to run Spring Boot WebMVC with Thymeleaf support - Stack...

java spring spring-mvc thymeleaf
Rectangle 27 1

Actually this has nothing to do with Spring Boot. As you mentioned, it supports both Java and XML bean configurations.

You can easily create multiple beans out of the same class using Java configuration.

<bean id="first" class="com.foo.MyClass" />

<bean id="second" class="com.foo.MyClass" />
@Configuration
class MyConfiguration {

    @Bean
    MyClass first() {
        return new MyClass();
    }

    @Bean
    MyClass second() {
        return new MyClass();
    }
}

This is possible. Usage of the @Qualifier annotation would also be recommended to avoid duplicate bean exceptions when using dependency injection.

Spring Boot - bean definition - Stack Overflow

spring spring-boot
Rectangle 27 2

WAS is an full blown Java Enterprise Application Server, on the other hand you have Spring that only requires a Servlet Container (Servlets are a part of full JEE).

Servlet Containers are for example: Tomcat, Jetty, but also WAS.

Spring Boot is able to package the complete application TOGETHER with the code of Tomcat in an JAR, so that this jar contains the Servlet Container and your Application.

  • Performance: No - There should be no important performance differerence between Tomcat and WAS when you run a Spring-Application. (Only that Tomcat needs less memory for itsself)
  • Stability: Tomcat and WAS are both very mature products.
  • Scaling: You can build a cluster of Tomcats by your own.

The main features of WAS over Tomcat are: - WAS supports EJB and CDI (Tomcat would need TomEE for this), but Spring will not use it, because it is its one Dependency Injection container - WAS has more Monitoring features, but this does not matter, because Spring Boot has Actuator

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

Does spring boot needs a WAS (Websphere Application Server)? - Stack O...

spring spring-mvc tomcat spring-boot websphere
Rectangle 27 2

WAS is an full blown Java Enterprise Application Server, on the other hand you have Spring that only requires a Servlet Container (Servlets are a part of full JEE).

Servlet Containers are for example: Tomcat, Jetty, but also WAS.

Spring Boot is able to package the complete application TOGETHER with the code of Tomcat in an JAR, so that this jar contains the Servlet Container and your Application.

  • Performance: No - There should be no important performance differerence between Tomcat and WAS when you run a Spring-Application. (Only that Tomcat needs less memory for itsself)
  • Stability: Tomcat and WAS are both very mature products.
  • Scaling: You can build a cluster of Tomcats by your own.

The main features of WAS over Tomcat are: - WAS supports EJB and CDI (Tomcat would need TomEE for this), but Spring will not use it, because it is its one Dependency Injection container - WAS has more Monitoring features, but this does not matter, because Spring Boot has Actuator

Does spring boot needs a WAS (Websphere Application Server)? - Stack O...

spring spring-mvc tomcat spring-boot websphere
Rectangle 27 1

I run all my tests over 6 classes of configuration/support.

@ActiveProfiles(resolver = TestActiveProfilesResolver.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest
@SpringApplicationConfiguration(classes = Application.class)
public abstract class AbstractTest {
   ...
}
@Transactional
public abstract class AbstractRepositoryTest<R> extends AbstractTest implements Repositories {

    @Inject
    private ObjectMapper mapper;

    @Inject
    protected Repositories repositories;

    private final Class<R> repositoryType;

    ...
}

AbstractIntegrationTest contains the core of my integration tests, utils methods to test controller's, etc.

public abstract class AbstractIntegrationTest extends AbstractTest {
    ...
}

Application provides to AbstractTest a context to run tests, this classe is same class that I use to run my spring boot application

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    ...
}

And finnaly the TestActiveProfilesResolver, that provide the profile to match application-test.properties, It's necessary because exist the open issue on JIRA, here

public class TestActiveProfilesResolver implements ActiveProfilesResolver {

    @Override
    public String[] resolve(final Class<?> testClass) {
        final String activeProfile = System.getProperty("spring.profiles.active");
        return new String[] {activeProfile == null ? "test" : activeProfile};
    }

}
AbstractRepositoryTest
AbstractIntegrationTests
AbstractServiceTest

java - Testing Spring boot REST resource issues - Stack Overflow

java rest testing spring-boot mockito