I have just met situation like that, I created default Spring framework from Spring tool suite, it will use slf4j and log4j for log everything into console.
After that, I add Spring security oauth dependency to maven, this dependency tree like :
spring security oauth --> spring boot --> spring boot starter --> logback(another logger).
The problem is my project had a logger, now spring boot add another logger, this make my logger work so strange (I used log4j.xml in classpath, level of logger is info but it print everything in debug level).
After I exclude logback from spring security oauth dependency from maven, log worked great, but I'm afraid of if I removed logback from spring boot starter, somewhere in this lib need logback, does it throw ClassNotFoundException?
Thanks in advance!
Update:
I copied pom file of spring security oauth2 from it's folder:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
Spring Security OAuth does not rely on Spring Boot. You probably have a different dependency that brings that.
Anyway, you can safely exclude logback, yes. Check also the documentation for more details.
Related
I setup Camunda in my Spring 3 project (Tomcat server) using this guide. I embedded the workflow engine in my project.
However, I cannot access the cockpit when I go to the url http://localhost:8080/camunda/app/. I get a 404 error.
I see that there is a dependency to be added in case of Spring boot according to this guide
But I see no such dependencies available for Spring. Do we not get access to webapps while integrating Camunda with Spring?
Also asked this question in the camunda form: https://forum.camunda.org/t/integrating-camunda-webapps-in-spring-framework/27661
You'll need the following dependency.
<dependency>
<groupId>org.camunda.bpm.webapp</groupId>
<artifactId>camunda-webapp-webjar</artifactId>
</dependency>
Then ensure you have the required configurations. Refer the spring boot auto configuration set up here and the web app initialiser here.
I have a simple question: I'm just getting started with Open API 3. For this purpose I have added the following dependency in Maven.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.30</version>
</dependency>
With the addition of this dependency, can I access the service via localhost:8082/v3/api-docs without having previously set anything and called a function of the dependency? How can this happen? What is the concept behind this ?
Adding the OpenAPI dependency in your Maven pom.xml just adds the librar(ies) to your project. That's all.
If this were a "traditional" project (like a JSP web app, for example), you'd have to write the code to create the web service (e.g. "localhost:8082/v3/api-docs").
But it sounds like your project might be Spring Boot:
https://developer.ibm.com/technologies/java/tutorials/j-spring-boot-basics-perry/
If you let it, Spring Boot will use its #EnableAutoConfiguration
annotation to automatically configure your application.
Auto-configuration is based on the JARS in your classpath and how
you’ve defined your beans:
Spring Boot uses the JARs you have specified to be present in the CLASSPATH to form an opinion about how to configure certain automatic
behavior. For example, if you have the H2 database JAR in your
classpath and have configured no other DataSource beans, then your
application will be automatically configured with an in-memory
database.
Spring Boot uses the way you define beans to determine how to automatically configure itself. For example, if you annotate your JPA
beans with #Entity, then Spring Boot will automatically configure JPA
such that you do not need a persistence.xml file.
It is called convention over configuration.
Wiki link https://en.wikipedia.org/wiki/Convention_over_configuration
I have seen a video whereby they enable debug logging for spring framework in a spring boot project. they created an application.properties file and entered logging.level.org.springframework = debug in the file.
I would like to do same for my application but I am not using spring boot. I have added dependencies like log4j but I am not sure about the settings.
Can someone share a link please?
thanks.
I want to use RestTemplate/TestRestTemplate by including the artifact in a SpringBoot application
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
But this automatically starts Tomcat or Jetty. Is there a way to turn it off, or by not including the above artifact. TestRestTemplate is in the boot artifact, but not the base RestTemplate.
Spring Boot is not going to start a web container if it's not present. spring-web does not provide any embedded container. You may want to analyse the dependencies of your project (try mvn dependency:tree).
If you want to make sure a web server is not started in your spring boot application, you can set the following configuration key
spring.main.web-application-type=none
Or you can use the SpringApplicationBuilder
new SpringApplicationBuilder(YourApp.class)
.web(WebApplicationType.NONE).run(args);
Since Spring Boot 2.0.0 this property is deprecated and following is the new way:
spring.main.web-application-type=none
This change is because Spring Boot the support for reactive server.
You can just close the app according to https://spring.io/guides/gs/async-method/. Although this still stars Tomcat, but will stop the app at the end without keeping the tread running.
SpringApplication.run(MyApp.class, args).close();
I am to use Dependency Injection of Spring framework version 4. I have seen that the Jersey has its DI with plugin
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.12</version>
</dependency>
Is Jersey's DI of Spring recommended or is there special reason to use it? What if Spring 4 DI is used independently ?
Also please let me know any step by step learning source to integration Spring DI with Jersey ?
The jersey-spring3 extension is not a stand-alone Dependency Injection feature, it's just an extension which makes Jersey aware of Spring's managed beans.
From Jersey - Spring DI:
Jersey provides an extension to support Spring DI. This enables Jersey to use Spring beans as JAX-RS components (e.g. resources and providers) and also allows Spring to inject into Jersey managed components.
...
The above module does not add any transitive dependency to Spring modules, so you will need to add Spring 3 dependencies explicitly into your dependency list.
So if you want to use Jersey with Spring you need jersey-spring3 and all the Spring dependencies you normally use.
By the way, the jersey-spring3 extension is compiled against Spring 3, but should work with Spring 4. See Using Jersey-spring with Spring 4.0 for reference.
You should add jersey-spring3.jar first like the document in jersey website.
For this step by step learning source to integration Spring DI with Jersey, you can do like this when you start up you application debug the application.
Find ServletContainer.class and set a breakpoint in init() function, as this you can find this step by step.