Spring MVC
Can Anyone Help here is the Code https://sourceb.in/fAubNQGQlP , Error : https://sourceb.in/idUMswCvoH
126 Replies
⌛
This post has been reserved for your question.
Hey @Danix! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
@dan1st | Daniel hey bro can u help me please
Caused by: java.lang.NoClassDefFoundError: antlr/collections/List
That's your problem.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
can u please ellaborate ? @sudha9163
@dan1st | Daniel hey broo can u look 0ver it and check the error bcz i am really stuck into it .
.
But i remove the class and found some other error that looks like this https://sourceb.in/fNII4Iux9
@dan1st | Daniel
What's the pom.xml? How do you run the application?
On server
and here is the pom.xml '
@dan1st | Daniel
I asked how, not where
and you don't need to ping me
How do u run the application? Means
Why are you using version 5.3.20 for spring-orm as opposed to 5.3.18?
How you are running the application
mvn spring-boot:run
?
Do you deploy a WAR file?No it's not a spring boot app it's spring MVC project
No
So how are you doing it?
I am deploy it to the tomcat server
and how?
Does that mean it isn't a WAR file?
Basically I am adding the project to the tomcat server like this
ok that's what I wanted to know
What about that?
Is there a reason for this?
Like I think this is the only way to start a project in spring MVC or in Servlets?
One of many 😄
So is this the actual reason why the error is coming?
I want to know about this
this could be the reason for the error
Unlikely
But now I have changed it
what did you change to what?
No idea, it seems that you removed the error.
From the version 5.3.20 to 5.3.18 of spring orm
.
Did that change anything?
Are you getting the same error again?
https://sourceb.in/SmRvywOPb7
here is the error
in think it is now changed
this is now how the code looks like https://sourceb.in/8OJ660Ck38
ok that seems somewhat better
looks like the
HibernateTemplate
has an issueLike how bcz i have provided it everything that it wants ...
Stack Overflow
No Bean Creation when Autowiring HibernateTemplate
I am creating a Spring Application but when I am Autowiring HibernateTemplate and running my application, I am getting BeanCreationException and it could not autowire HibernateTemplate.
Stack Trace...
there was only one single answer and i think its correct in my project
I don't know if beans defined in XML are any different, but you can try adding
@Qualifier("hibernateTemplate")
Nahh that doesn't work
Do you have a web.xml?
Yehh
Do you have anything else in the WEB-INF?
this is how it looks likes
What's the config.xml?
The spring configuration
try adding that to the web.xml
https://sourceb.in/mmrrpBLKq9 i think the issue is still same
that's a different error
Ohh yehh
Stack Overflow
"java.lang.TypeNotPresentException: Type org.hibernate.SessionFacto...
I have "java.lang.TypeNotPresentException: Type org.hibernate.SessionFactory not present " Error when trying to run spring MVC project with hibernate + tomcat on intelliJIdea.
Here is my Depende...
Do you have hibernate-core in your pom.xml?
Yehh
Can you try changing the version of hibernate-core to 5.5.4?
actually 5.6.7.Final is probably better
and 6.2.3.Final for Hibernate validator
see https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.6.6/spring-boot-dependencies-2.6.6.pom for versions that should match
the error
https://sourceb.in/q6MmhGqBfV
.
in your pom.xml
i did it
but still facing the error
Can you show it?
yeh sure
Did you reload the Maven project and restart tomcat after the change?
yeh
alt +f5 in eclipse
https://sourceb.in/sH4BqpnAM5
Do you have a build directory in the project?
or target
What's in WEB-INF/lib?
This is inside of the lib folder
this is what target folder have inside
You could try putting hibernate and other dependencies into WEB-INF/lib
if you don't know how to do that, you could also get Maven to do it
how to do it
?
I'm currently writing the configuration for it
You could try adding this to the pom.xml
this should attempt to copy the hibernate stuff to WEB-INF/lib
After doing that, it should look like this
Essentially that configures the dependency plugin (which manages dependencies) to automatically copy certain dependencies in the
generate-resources
phase. It is then configured to only do this for dependencies in org.hibernate
with the scope compile
(the default scope) and to copy it to WEB-INF/libSo when i shift to spring boot from this then should i have to do it everytime
THis is normally not necessary with Spring Boot
Does it fix the error?
No 🙁
here is the error https://sourceb.in/sNkNTvjYmC
if you change
<outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
to <outputDirectory>${project.basedir}/src/main/resources/WEB-INF/lib</outputDirectory>
, it doesn't change anything, right?another thing yu could try is to right-click your project and select build path>configure build path. There, check
Maven Dependencies
under Order and Export
https://sourceb.in/evukY5GBoo The error i got after doing this !
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Hey did u find why the error is coming @dan1st | Daniel
tbh idk
Actually what's your
LoginPage
?
Maybe the issue is with your config.xml
and maybe you could try thatIn the build path, go to
Add Library
select
Web App Libraries
make sure the right project is selected
and click
Finish
then it should look somewhat like that
Actually when did not connect the spring with orm then it was working fine but when I connected it with orm and try to get hibernate Template then it starts giving me errors
Do you really need
HibernateTemplate
?
I think HibernateTemplate
doesn't even exist in newer Spring versions (you are using an old version of Spring)So then how to work with orm in spring?
I think you are right bcz the video which I am following rn is 3 yrs old and in the comments people are also getting the same type of error as me
I think its's possible to directly use
SessionFactory
instead of HibernateTemplate
videos are a problem in generalHmm yehh u are right
So now what should I have to remove from my config.xml
maybe everything related to
HibernateTemplate
?
But I think you have problems with SessionFactory
, right?Yehh
If you show me your current web.xml, config.xml and controller (as text, not with images or links to other sites), I may be able to reproduce it by myself
What's
com.controllers.Database.DaoEntity
?its database entity where i have made dao inteface and its implemented class and a Dao Entity
which i have creted using hibernate
ok so for me it works but I made some changes
since you now don't have the dispatcherservlet.xml in your web.xml, I added this to the
config.xml
:
also if yoou expand Web App Libraries>hibernate-core and select dialect, is there a
MySQL55Dialect
or MySQL8Dialect
class there?yehh it is here
Which one is there?
The thing is that I'm using a newer version of all of these things so a bit of it is different
but it does work for me
there are 2 of them 1st is MySQL8Dialect.class and the second one is MySQL55Dialect.class as well
ok I think
MySQL8Dialect
is better for you
so in your config.xml
, also change <prop key="hibernate.dialect">org.hibernate.dialect.MySQL55Dialect</prop>
to <prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
and you also have this in the config.xml
:
comment this out
i.e. you can replace it with
and it will no longer be active
and after you did all that, tell me what happensso i have to change the dialect from 55 to 8 and comment this out right ?
yes
and don't forget about that
because you have the config.xml instead of the dispatcherservlet.xml now so you still need these parts
so u mean i have to add these lines to the config.xml aswell
?
@dan1st | Daniel
which lines?
yes
if you still want to use JSP, you probably need it
but i already have it in dispatcher-servlet.xml
Well you no longer use that in your web.xml, right?
ohh yeh i have passed the name of the config.xml file in the web.xml
so now i got another error bcz i have also comment out the hibernate template bean
https://sourceb.in/waPH7hhCtd
@dan1st | Daniel
How is that another error?
Also why do you use that sourcebin site instead of just posting these things in Discord using a codeblock?
The config file now
You still have this
Try commenting this out as well
Also can you show the code you are using
HibernateTemplate
with? You likely need to change it
For me, it's possible to use Hibernate somewhat like that (using SessionFactory
and not HibernateTemplate
):
btw please follow naming conventions in your code if possible: https://discord.com/channels/648956210850299986/1241797526374580325/1244581989864964109Naming conventions ensure that projects have similar names and allow to distinguish e.g. packages, classes and methods/variables. For that, it is important developers don't mix naming conventions.
Most Java code follows these naming conventions:
- Type names (e.g. classes or interfaces) should be PascalCase meaning the first letter of every word is written in uppercase while all other letters are lowercase.
- Constants are ALL_UPPERCASE_SEPARATED_BY_UNDERSCORES.
- Other variables (both fields and local variables) as well as methods are camelCase. This means the identifiers start with a lowercase letter, all subsequent words start with an uppercase letter and all other letters are lowercase.
- Package names are all_lowercase whereas dots are used to create a hierarchy of packages. All packages of an application are typically grouped together in some top level package. This typically uses reverse domain name notation. For example, an application called
MyApplication
maintained by a company/individual owning the domain example.com
would put all its classes in a package named com.example.myapplication
or subpackages.
There are other naming conventions as well (for example prepending getters with get
and setters with set
, e.g. getMyVariable
/setMyVariable
.
Aside from that, projects may have specific naming conventions.
here is the class where i am using the Hibernate Template
try it like this:
Alternatively you could replace the constructor with
Alternatively if you want to use
@Transactional
, you could try this:
Ok I will try it later after reaching my home
But can you tell me please bro can I skip the spring MVC project bcz like I have completed the basics annotation and basic understanding of spring MVC so can I go for spring boot directly or stayed with it and make projects ?
yeah sure
Does it effect anything in my future ?
What specifically?
In most cases, Spring is used with Spring Boot
and tbh I've never used Spring without Spring Boot but as you have probably seen, I understand how it works enough so I can probably fix most problems (if I encounter a problem, I am more likely to properly understand it than when someone else encounters it because if it's on my machine, I can easily reproduce it and it's also something important for me so I'm willing to spend time on it)
So essentially I don't think you need to know how to use everything with Spring without Spring Boot but it's good to understand how these things work
So directly jumping into spring boot now will not be the bad decision for me .. And the main reason I am thinking to directly switch to spring boot is bcz i have completed spring core , spring MVC basics , spring with orm so I think this is enough to jump to spring boot right?
Does it important to learn spring JDBC Module as well ?
You can also use Spring JDBC with Spring Boot
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.