Coexistence of both thymeleaf and jasper files in Spring Boot application - spring-boot

I tried, in a project both jasper and thymeleaf, but can not coexist, as I would like to use jsp must comment out Spring-boot-starter-thymeleaf depend on the package, so that it can run. Looking for a solution so that both jasper and thymeleaf can co exist. I got a solution on stackoverflow if some one use servlet-context.xml ( Mixing thymeleaf and jsp files in Spring Boot ), where both jasper and thymeleaf coexist. But my requirement is how to include those attributes in pom.xml if I am using spring-boot-starter-web.

I was able to run both HTML and JSP page from embedded jar build inside Spring boot. But if you like to run it independently by copying the Jar in command prompt then you need to copy the JSP page folder structure as it will not be in the jar content and you need to change the pom file little bit so that the jar can add external content to it.
STEP 1: Add Thymeleaf and JSP dependencies
Add below dependencies to your pom.xml file
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
STEP 2: Project structure and file creation
Under source folder src/main/resources create folder templates, under that create sub-folder thymeleaf. And create a html file sample.html(say)
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
</head>
<body>
THYMELEAF PAGE: <p th:text="${name}"></p>
</body>
</html>
Under src/main/webapp/WEB-INF create sub-folder views. Under views create a jsp file, sample.jsp(say)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello</title>
</head>
<body>
JSP PAGE: Hello ${name}
</body>
</html>
STEP 3: In your application.properties set thymeleaf view names and JSP configuration for internal view resolution.
#tomcat-connection settings
spring.datasource.tomcat.initialSize=20
spring.datasource.tomcat.max-active=25
#Jasper and thymeleaf configaration
spring.view.prefix= /WEB-INF/
spring.view.suffix= .jsp
spring.view.view-names= views
spring.thymeleaf.view-names= thymeleaf
#Embedded Tomcat server
server.port = 8080
#Enable Debug
debug=true
management.security.enabled=false
STEP 4: Create controller for serving Thymeleaf and JSP pages:
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
#Controller
public class TestController {
#RequestMapping(value="/jasper", method=RequestMethod.GET)
public String newjasper(Map<String, Object> m, String name){
//System.out.print("-- INSIDE JSP CONTROLER ------");
m.put("name", name);
return "views/sample";
}
#RequestMapping(value="/thymeleaf", method=RequestMethod.GET)
public String newthymeleaf(Map<String, Object> m, String name){
//System.out.print("-- INSIDE HTML CONTROLER ------");
m.put("name", name);
return "thymeleaf/sample";
}
}
STEP 5: Some cases you may required to create a configuration class SpringConfig.class (say) for view resolution for JSP pages. But optional, I don't use it in my configuration file.
import org.springframework.web.servlet.view.JstlView;
#Configuration
public class SpringConfig {
#Value("${spring.view.prefix}")
private String prefix;
#Value("${spring.view.suffix}")
private String suffix;
#Value("${spring.view.view-names}")
private String viewNames;
#Bean
InternalResourceViewResolver jspViewResolver() {
final InternalResourceViewResolver viewResolver = new
InternalResourceViewResolver();
viewResolver.setPrefix(prefix);
viewResolver.setSuffix(suffix);
viewResolver.setViewClass(JstlView.class);
viewResolver.setViewNames(viewNames);
return viewResolver;
}
}
STEP 6: Testing application for both jsp and html.
When you hit this url in your browser: http://localhost:8080/thymeleaf?name=rohit . This will open our sample.html file with parameter name in center of page and with this url: http://localhost:8080/jasper?name=rohit will open sample.jsp page with parameter name in center.

from the viewresover javadoc.
Specify a set of name patterns that will applied to determine whether
a view name returned by a controller will be resolved by this resolver
or not.
In applications configuring several view resolvers –for example, one
for Thymeleaf and another one for JSP+JSTL legacy pages–, this
property establishes when a view will be considered to be resolved by
this view resolver and when Spring should simply ask the next resolver
in the chain –according to its order– instead.
The specified view name patterns can be complete view names, but can
also use the * wildcard: "index.", "user_", "admin/*", etc.
Also note that these view name patterns are checked before applying
any prefixes or suffixes to the view name, so they should not include
these. Usually therefore, you would specify orders/* instead of
/WEB-INF/templates/orders/*.html.
Specify names of views –patterns, in fact– that cannot be handled by
this view resolver.
These patterns can be specified in the same format as those in
setViewNames(String []), but work as an exclusion list.
viewResolver.setViewNames(viewNames);

Related

spring boot jsp file can not be viewed

I'm using spring boot application. I have set the MvcConfig class for it and added tomcat-embed-jasper and jstl dependencies to pom.xml. However, I can not view my jsp file in the 'WEB-INF' folder, I will get 404 error (Whitelabel Error Page).I have set the Application.properties. here is my application.properties:
#
## View resolver
#
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
Here is my MvcConfig class:
package com.goodvideotutorials.spring.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
#Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
#Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
}
}
Here is my home.jsp:
<%# page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Up and running with Spring Framework quickly</title>
</head>
<body>
<h2>Hello, world!</h2>
</body>
</html>
it is inserted inside src > main > webapp > WEB-INF > jsp > home.jsp
I have added these dependencies to pom.xml:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
this is my Application.java class:
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
and my controller class:
#Controller
public class RootController {
// #RequestMapping("/")
// public String home() {
//
// return "home";
//
// }
}
Any way if I make the code commented in the controller and don't use MvcConfig, it doesn't work. If I comment that code and use MvcConfig class, it doesn't work as well. This is the url : localhost:8080
I just tested many things , but it shows "Whitelabel Error Page" instead of JSP. I also have Tomcat server installed in the JEE environment. Could that cause problem?
just my 2 cents.
For me i received the following warning in server logs :
WARN : ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/welcome.jsp]
and the white label error page was displayed, to fix it i modifed my JSP location
from
src/main/webapp/WEB-INF/jsp/welcome.jsp
to
src/main/webapp/templates/jsp/welcome.jsp
Why it worked for me ?
Spring documentation clearly states that ResourceHttpRequestHandler will reject any URL that contains either WEB-INF or META-INF.
ResourceHttpRequestHandler doc link
From DOCS: Identifies invalid resource paths. By default rejects:
Paths that contain "WEB-INF" or "META-INF"
Hence as soon as i replaced the WEB-INF folder name with templates, it started working.
Note :
I also had my internal view resolver configured with required prefix and suffix.
I am using spring-boot-starter-parent - 2.1.2.RELEASE
Spring boot help you automatically by:
Add file src/main/resources/application.properties:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
And dependency:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Or You should add configuration for view resolver like:
#Configuration
#EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
#Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
#Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Change your Application like:
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Follow below steps
1 - tomcat-embed-jasper dependency
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
2 - Add below configuration is application.properties
spring.mvc.view.prefix: /
spring.mvc.view.suffix: .jsp
3 - whatever JSP page you want to show so for that add below code in controller
#RequestMapping("/")
public String welcome(Model model) {
model.addAttribute("message", "Hello World !!!");
return "welcome";
}
so based on above code it will look for welcome.jsp file in webapps/welcome.jsp
That's it still have some doubt then check it out below link
Spring Boot and JSP Integration
The problem is caused by the <scope> of the org.apache.tomcat.embed dependency.
To resolve the <scope>provided</scope> line. So, the dependency looks like :
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
The scope provided is only available on the compilation and test classpath not at the runtime. It is not transitive as default scope compile.

Spring defaultHtmlEscape doesn't prevent xss attack

I want to prevent xss attacks in my spring application.
I added
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
into my web.xml (I found this soulution here)
but on my page I save content with name <script>alert(1);</script> and this scripts executes after page refresh.
client side code:
$.ajax({
type: 'POST',
url: 'setContentName',
dataType: 'json',
data: {contentId: id, name: params.value}
});
What do I wrong?
P.S.
I load content using javascript after refresh
Mine is a somewhat controversial opinion, but I think you should validate and reject inbound XSS. You should escape it on output too, but it shouldn't be in your database in the first place, as dbs are long-lasting and often cross-application.
See https://www.owasp.org/index.php/OWASP_JSON_Sanitizer
Use Hibernate Validator (you don't need to use Hibernate ORM) with JSoup to avoid XSS in your db:
Foo.java:
#Entity
class Foo {
#SafeHtml(whitelistType = SafeHtml.WhiteListType.NONE)
private String name;
...
}
FooController.java:
#Controller
public class FooController {
#RequestMapping(method=POST)
String submit(#Validated Foo foo) {
...
}
}
pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.1</version>
</dependency>
See Adding additonal Security to Website for more anti-XSS measures
I use JSTL for the purpose. Include c prefix in the jsp page,
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
For the value you want to show
<c:out value=${someVar} escapeXml="true" />
Setting the attribute excapeXml="true" is optional in this scenario because its default value is true
Oracle Documentation

Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers

This question has been asked before but I did not solve my problem and I getting some weird functionality.
If I put my index.html file in the static directory like so:
I get the following error in my browser:
And in my console:
[THYMELEAF][http-nio-8080-exec-3] Exception processing template "login":
Exception parsing document: template="login", line 6 - column 3
2015-08-11 16:09:07.922 ERROR 5756 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].
[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet]
in context with path [] threw exception [Request processing failed; nested
exception is org.thymeleaf.exceptions.TemplateInputException: Exception
parsing document: template="login", line 6 - column 3] with root cause
org.xml.sax.SAXParseException: The element type "meta" must be terminated by
the matching end-tag "</meta>".
However if I move my index.html file into the templates directory I get the following error in my browser:
I have added my view resolvers:
#Controller
#EnableWebMvc
public class WebController extends WebMvcConfigurerAdapter {
#Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
registry.addViewController("/results").setViewName("results");
registry.addViewController("/login").setViewName("login");
registry.addViewController("/form").setViewName("form");
}
#RequestMapping(value="/", method = RequestMethod.GET)
public String getHomePage(){
return "index";
}
#RequestMapping(value="/form", method=RequestMethod.GET)
public String showForm(Person person) {
return "form";
}
#RequestMapping(value="/form", method=RequestMethod.POST)
public String checkPersonInfo(#Valid Person person, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "form";
}
return "redirect:/results";
}
#Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("templates/");
//resolver.setSuffix(".html");
return resolver;
}
#Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
WebSecurityConfig.java
#Configuration
#EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<meta>
<meta> charset="UTF-8">
<title></title>
</head>
<body>
<h1>Welcome</h1>
<span>Click here to move to the next page</span>
</body>
</html>
At this point I do not know what is going on. Can anyone give me some advice?
Update
I missed a typo in index.html, but I am still getting the same errors
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta> charset="UTF-8">
<title></title>
</head>
<body>
<h1>Welcome</h1>
<span>Click here to move to the next page</span>
</body>
</html>
Check for the name of the
templates
folder. it should be templates not template(without s).
index.html should be inside templates, as I know. So, your second attempt looks correct.
But, as the error message says, index.html looks like having some errors. E.g. the in the third line, the meta tag should be actually head tag, I think.
In the console is telling you that is a conflict with login. I think that you should declare also in the index.html Thymeleaf. Something like:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>k</title>
</head>
I am new to spring spent an hour trying to figure this out.
go to --- > application.properties
add these :
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
this can be resolved by copying the below code in application.properties
spring.thymeleaf.enabled=false
this make me success!
prefix: classpath:/templates/
check your application.yml
If you are facing this issue and everything looks good, try invalidate cache/restart from your IDE. This will resolve the issue in most of the cases.
this error probably is occurred most of the time due to missing closing tag. and further you can the following dependency to resolve this issue while supporting legacy HTML formate.
as it your code charset="UTF-8"> here is no closing for meta tag.
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
For me the issue was because of Case sensitivity. I was using ~{fragments/Base} instead of ~{fragments/base} (The name of the file was base.html)
My development environment was windows but the server hosting the application was Linux so I was not seeing this issue during development since windows' paths are not case sensitive.
The error message might also occur, if the template name starts with a leading slash:
return "/index";
In the IDE the file was resolved successfully with a path with two slashes:
getResource(templates//index.html)
Delegating to parent classloader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#2399ee45
--> Returning 'file:/Users/andreas/git/my-project/frontend/out/production/resources/templates//index.html'
On the productive system, where the template is packed into a jar, the resolution with two slashes does not work and leads to the same error message.
✅ Omit the leading slash:
return "index";
Adding spring.thymeleaf.mode=HTML5 in the application.properties worked for me. You could try that as well.
I also faced TemplateResolver view error , Adding the spring.thymeleaf.mode=HTML5 in the application.properties worked for me. In case of build created in STS and running for Websphere 9 ..
Check the html file is available in src/main/resources/templates folder
Try adding #RestController as well,
I was facing this same problem, i added both #RestController #Controller, it worked find
It May be due to some exceptions like (Parsing NUMERIC to String or vise versa).
Please verify cell values either are null or do handle Exception and see.
Best,
Shahid
I wasted 2 hours debugging this issue.
Althought I had the template file in the right location (within resources/templates/), I kept getting the same error.
It turns out it was because I had created some extra packages in my project. For instance, all controller files were in 'controller' package.
I did the same thing for the files which were automatically generated by Spring Initializr.
I don't understand exactly why this happens,
but when I moved the ServletInitializer file and the one annotated with #SpringBootApplication back to the root of the project, the error went away !
For me, including these in the pom.xml CAUSES the exception. Removing it from the pom.xml resolves the issue.
(Honestly, I don't know how that happen)
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.outputDirectory}</targetPath>
<includes>
<include>application.properties</include>
</includes>
</resource>
</resources>
</build>
In my case I had everything else right as suggested above but still it was complaining that "template might not exist or might not be accessible by any of the configured Template Resolvers". On comparing my project with some other sample projects which were working fine, I figured out I was missing
<configuration>
<addResources>true</addResources>
</configuration>
in spring-boot-maven-plugin. Adding which worked for me. So my plugins section now looks like
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
I am not sure why I needed to add tag to get thymeleaf working though.
I tried all the solutions here and none of them seemed to be working for me
So I tried changing the return statement a little bit and it worked!
Seems like the issue with thymleaf not being able to recognize the template file, adding ".html" in the return statement seemed to fix this
#RequestMapping(value="/", method = RequestMethod.GET)
public String getHomePage(){
return "index.html";
}

Issue with creating Custom Tag Libraries in CQ5.5

I am creating a custom tag library and want to use it in one of my components. I have created a bundle which includes tag hello class which is extending TagSupport class and i created tags.tld file under my resource folder
In my pom.xml, I have used resource tag to include my .tld file in the generated jar file.
Here is my java class and tld file
TAG CLASS:-
package com.cb;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* Simple tag example to show how content is added to the
* output stream when a tag is encountered in a JSP page.
*/
public class Hello extends TagSupport {
private String name=null;
/**
* Getter/Setter for the attribute name
as defined in the tld file
* for this tag*/
public void setName(String value){
name = value;
}
public String getName(){
return(name);
}
/**
* doStartTag is called by the JSP container
when the tag is encountered */
public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.println("<table border=\"1\">");
if (name != null)
out.println("<tr><td> Welcome <b>" + name +
"</b> </td></tr>");
else
out.println("<tr><td> Hello World </td></tr></table>");
} catch (Exception ex) {
throw new Error("All is not well in the world.");
}
// Must return SKIP_BODY because we are not
//supporting a body for this
// tag.
return SKIP_BODY;
}
/**
* doEndTag is called by the
JSP container when the tag is closed */
public int doEndTag(){
return EVAL_PAGE;
}
}
I also successfully installed the bundle in my felix console without having any error. Then i written custom tag in my jsp as below
JSP:-
<%#include file="/libs/foundation/global.jsp"%>
<%# page import="com.testcb.TestCustomTag"%>
<%# taglib prefix="mytest" uri="http://cs.test.com/bundles/cq/1.8"%>
<mytest:hello name="sachin"></mytest:hello>
I am getting the like "org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: /apps/test/components/content/test/test.jsp(4,0) Unable to load tag handler class "com.cb.Hello" for tag "mytest:hello".
The same code is working fine in my apache tomcat server without having any issue. I am getting the error when i incorporate it in CQ.
What am i doing here? Is there any config i need to do in OSGI console to make it available?
UPDATE:
There was some problem with package name. Now Sling can read my tag handler class after i renamed the package name.
The error "Unable to load tag handler class" also has gone.
Now i am getting error as "org.apache.sling.api.scripting.ScriptEvaluationException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.testcb.TestCustomTag cannot be cast to javax.servlet.jsp.tagext.Tag"
I have the following dependency in pom.xml
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
And Here is my tld
<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<description>My tag library123</description>
<tlib-version>1.0</tlib-version>
<short-name>TagLib-Test</short-name>
<uri>http://cs.test.com/bundles/cq/1.0</uri>
<jspversion>2.1</jspversion>
<tag>
<name>testcustomtag</name>
<tagclass>com.testcb.TestCustomTag</tagclass>
<bodycontent>empty</bodycontent>
<info>This is a simple hello tag</info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
Is there any problem with jsp version?
Please guide me to resolve.
Thanks
The tags.tld file needs to be under the META-INF folder. If you don't have it already you can create one under your resources source folder.
Yes, It is working as expected after i removed tag in pom.xml. This was the cause issues. :)
Thanks !

TilesConfigurer is deprecated ?? How I use tile2.2 in spring MVC 3.1?

I try to integrate Spring MVC 3.1 with Apache Tile2.2 but I found this error
Error creating bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/tiles-context.xml]: Invocation of init method failed
so I search it in google and I found in Apache Tile2 structure had change or deprecated but spring mvc 3.1 still use old structure. (Someone said We must modify the class or etc.)
These are my lib I used:
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-el-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
adn spring mvc
org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.aspects-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context.support-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.instrument.tomcat-3.1.0.M1.jar
org.springframework.instrument-3.1.0.M1.jar
org.springframework.jdbc-3.1.0.M1.jar
org.springframework.jms-3.1.0.M1.jar
org.springframework.orm-3.1.0.M1.jar
org.springframework.oxm-3.1.0.M1.jar
org.springframework.test-3.1.0.M1.jar
org.springframework.transaction-3.1.0.M1.jar
org.springframework.web.portlet-3.1.0.M1.jar
org.springframework.web.servlet-3.1.0.M1.jar
org.springframework.web.struts-3.1.0.M1.jar
org.springframework.web-3.1.0.M1.jar
Anyone know how I fix this ? It will be useful to me.
If you import from org.springframework.web.servlet.view.tiles3 package you will not get any depricated issue but if you import from org.springframework.web.servlet.view.tiles2 it is depreciated. I solved the issue by changing imports.
Configuration class
package mum.waa;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
#Configuration
public class TilesConfiguration{
public TilesConfigurer tilesConfigurer()
{
final TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] { "WEB-INF/tiles.xml" });
configurer.setCheckRefresh(true);
return configurer;
}
#Bean
public TilesViewResolver tilesViewResolver() {
final TilesViewResolver resolver = new TilesViewResolver();
resolver.setViewClass(TilesView.class);
return resolver;
}
}
Dependencies
<!-- Apache Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.7</version>
</dependency>
<!-- Apache Tiles -->
(Answered by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
solution:
This is not error by deprecated it's about jar file that didn't right version.
I solved by find right jar to my web application
this is my jar
commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-digester-2.1.jar
jcl-over-slf4j-1.6.3.jar
slf4j-api-1.6.3.jar
slf4j-log4j12-1.6.3.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
For some people get lost like me, Mart

Resources