Tag Archives: SSM

[Solved] javax.servlet.ServletException: Servlet[springmvc] Servlet.init()

1. There are many cases of this exception. First of all,
when configuring sqlsessionfactorybean, you should not pay attention to the problem (see the figure)

the same as above, when configuring other places, you also use ref as value. For example,

PS: combined with the above, it can discharge itself. Pay attention to whether it is this problem

2. Problems that we didn’t pay attention to when configuring servlets with web.xml

as shown in the figure: after the integration, the configuration file should not be MVC, but should be all. Generally, when creating a configuration file, there will be a prompt in the upper right corner, which may cause this kind of problem if you don’t pay attention to it. Generally, my solution is to use the import tag (as shown in the figure)

import all the configuration files into a general file
and then import the web and XML into the general file as follows

PS: there are some special reasons, which vary from person to person. Hope someone can add!

[Solved] You must configure either the server or JDBC driver (via the ‘serverTimezone‘ configuration proper

This error occurs when running the example
2021-06-25 10:14:14.571 ERROR 10096 — [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utilize time zone support.] with root causeSolution:

add the following codes to application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/you_mysql?serverTimezone=UTC

SSM project controller layer calls static method to report an error

The controller layer of the SSM project calls the util tool class written by oneself. In the tool class, some static methods in some jar packages are invoked, and
runs up to report errors. Br> solution: add the jar package to the modules directory in the project
idea operation:
. Add through dependencies of modules:
1. Open file – & gt; Project Structure (Ctrl + Shift + Alt + S)

2. Click modules – & gt; Dependencies -> “+” -& gt; “ Jars or directories”

3. Select the project jar package
4. Apply – & gt; OK

SSM custom 404 and 500 error reporting interface

SSM custom 404 and 500 error reporting interface

1. In web.xml Configuration 2, test 404 error

1. In web.xml Medium configuration

 <!--Replace the 400 and 500 error message screens-->
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/error/404.jsp</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/error/500.jsp</location>
  </error-page>

2. Test 404 error

As shown in the figure below, is the effect much more comfortable than a pile of newspapers.

Error creating bean with name ‘xxcontroller’

Today, when we learn to integrate SSM projects to test whether the framework is available, we will report the above error as soon as we run Maven’s Tomcat,

At the beginning, I thought it was because the service layer annotation was not well written. After checking, I found that there was no error. Finally, in the web.xml It is found that the following param value is wrongly written in the file, and the application in ApplicationContext – *. XML is missing an n.

≪! — load the spring container — & gt;
& lt; context param & gt;
& lt; param name & gt; contextconfiglocation & lt; & param name & gt;
& lt; param value & gt; classpath:spring/applicationContext- *.xml</param-value>
  </context-param>

And less in the transaction aspect

< aop:config>
< aop:advisor advice-ref= “txAdvice”
pointcut=”execution(* cn.itcast .e3 mall.service ..*.*(..))” />
</ aop:config>

Spent a lot of time, finally solved, hope to help you!

Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project

Complete error message

Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project jurisdiction_controller: Could not start Tomcat


Start the Maven project wrong, use Tomcat embedded in it
The solution
The dependent use of servlets is introduced in the pom.xml file


Change after

add scope tags, and the values is provided (only role in the compilation and testing, and at the same time not pass)
The scope label specifies the range of values
compile
The default scope, which means that all Dependencies can be used throughout the lifecycle. Furthermore, these dependencies are passed to the projects on which they depend. Applies to all phases and will be released along with the project
provided
Similar to compile, but indicating that dependency is provided by JDKs or containers, such as Servlet APs and some Java EE APIs. This scope can only be used during compilation and testing and has no transitivity.
runtime
Dependency does not apply at compile time, but does apply at run and test times, such as JDBC drivers, for the run and test phases.
test
Indicates that dependency is applied at test time, not at run time. Used only during testing, to compile and run test code. Will not be released with the project.
system
Similar to Provided, but provided in the system as an external JAR, Maven does not look for it in a repository.

Solution to the error of @ resource annotation in eclipse spring

The @Resource annotation in Eclipse-Spring is used to report an error

1. Problems arise


2. The cause of the problem
@ the Resource is equivalent to the applicationContext. GetBean method, is the annotation – API. The class in the jar package, only support is jdk1.6 annotations, and their default is jdk1.5 (pictured) of the project, so the JDK version because the project is too low, there is an error.

3. Solutions
1. Place the cursor on the project — right click — find Build Path — and then go to Configure Build Path (select)

.
> Find the Java Bulib Path — Libraries — Select the default JRE System Library[J2SE-1.5] — double-click — check Workspace Default JRE (JRE 1.8.0_121)* (this will work if you change to the latest)*.
the default format:
to this format:

4, successfully solved the
modification is done, another to write @ Resource annotation automatically prompts, and there is no error

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded (How to Fix)

when setting up springboot, boot fails with the error

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

the solution: add a exclude = DataSourceAutoConfiguration. Class

before:

package App;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

after:

package App;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class App {
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

works normally, solve


  .   ____          _            __ _ _
 /\\/___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, |////
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2018-10-13 10:38:15.265  INFO 7288 --- [           main] App.App                                  : Starting App on Y9SVAFMN942HYRY with PID 7288 (D:\boot_1\target\classes started by Administrator in D:\boot_1)
2018-10-13 10:38:15.271  INFO 7288 --- [           main] App.App                                  : No active profile set, falling back to default profiles: default
2018-10-13 10:38:15.453  INFO 7288 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@50a6f6: startup date [Sat Oct 13 10:38:15 CST 2018]; root of context hierarchy
2018-10-13 10:38:18.881  INFO 7288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-10-13 10:38:18.942  INFO 7288 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-13 10:38:18.942  INFO 7288 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-13 10:38:18.967  INFO 7288 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_161\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_161/bin/client;C:/Program Files/Java/jre1.8.0_161/bin;C:/Program Files/Java/jre1.8.0_161/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\namd-tutorial\NAMD_2.8\NAMD_2.8_Win32-multicore;D:\Program Files\Anaconda3;D:\Program Files\Anaconda3\Scripts;D:\Program Files\Anaconda3\Library\bin;;D:\eclipse-jee-oxygen-3-win32\eclipse;;.]
2018-10-13 10:38:19.506  INFO 7288 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2018-10-13 10:38:19.515  INFO 7288 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-13 10:38:19.515  INFO 7288 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4066 ms
2018-10-13 10:38:20.059  INFO 7288 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-10-13 10:38:20.068  INFO 7288 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-10-13 10:38:20.069  INFO 7288 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-10-13 10:38:20.069  INFO 7288 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-10-13 10:38:20.070  INFO 7288 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-10-13 10:38:20.367  INFO 7288 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-13 10:38:20.993  INFO 7288 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@50a6f6: startup date [Sat Oct 13 10:38:15 CST 2018]; root of context hierarchy
2018-10-13 10:38:21.159  INFO 7288 --- [           main] 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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-10-13 10:38:21.162  INFO 7288 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-10-13 10:38:21.216  INFO 7288 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-13 10:38:21.216  INFO 7288 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-13 10:38:21.662  INFO 7288 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-10-13 10:38:21.920  INFO 7288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-13 10:38:21.926  INFO 7288 --- [           main] App.App                                  : Started App in 7.938 seconds (JVM running for 8.682)